Frage

I am using LambdaJ and hamcrest in Java. I am wondering if there is a way to check if any item in one array is equal to any item of another array?

I have tried some configurations but I can not seem to get it right.

like this one:

arrayOne, hasItemInArray(isIn(arrayTwo));

... Does not work because it will try to match every item in arrayOne.

War es hilfreich?

Lösung

I think I solved it!

The problem was not that Hamcrest does not match the way I described in the question. It was that I had a List of Long:s.

I was refering to hasItemInArray which uses hasValue (comparing primitive types) rather than hasItem (comparing objects).

So the code above works with a minor modification:

arrayOne, hasItem(isIn(arrayTwo));

This is acually a somewhat confusing naming convention.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top