Question: I am trying to assert that an array of string elements is one of the elements of a 2-dimensional array using the standard **Collection.isIn** matcher provided with Hamcrest library. Unfortunately receiving the following assertion exception: 

```
java.lang.AssertionError: 
Expected: one of {["A", "B", "C"], ["A", "B", "C"]}
   but: was ["A", "B", "C"]

```

**Code:**

```
String[][] expected = new String[][] { { "A", "B", "C" }, { "A", "B", "C" } };
String[] actual = new String[] { "A", "B", "C" };

assertThat(actual, isIn(expected));

```

Can I validate using hamcrest in such a manner? Or do I need to create my own matcher for the given scenario?

Answer: 
First of all, you would be better off using `List<>` instead of arrays.

Secondly, yes, if you insist on using arrays, you will need to write your own 'array-contains-element' function. You can implement this function using a loop over the major dimension of the array, invoking the `Arrays.equals()` method to compare the contents of two one-dimensional arrays.
The problem with collection.IsIn in your context, is that your elements of your list is an array and it will use the Array#equals to compare each element.

More specifically

```
// It will print false, because Array.equals check the reference 
// of objects, not the content
System.out.println(actual.equals(new String[]{"A1 C1 E1 F1 J1", "A1 C1 E1 F1 K1", "A1 B1 G1 H1"}));

```

So I suggest creating a custom matcher that uses Arrays.equals from java. It will compare the content of arrays for you. Something like code below:

```
public boolean matches(Object item) {
    final String[] actualStringArray = (String [])item;

    List<String[]> listOfStringArrays = Arrays.asList(expectedStringMatrix);

    for (String[] stringArray : listOfStringArrays) {
        // Arrays.equals to compare the contents of two array!
        if (Arrays.equals(stringArray, actualStringArray)) {
            return true;
        }
    }
    return false;
}

```