Reputation: 47280
Or is there ?
I just have
int[] results
and want to check each element in array has the same int value.
(yeah I could just loop through them).
Upvotes: 0
Views: 57
Reputation: 20254
There's no need to loop, just convert the array into a Set object and then check its length, if the length is 1 then everything in the array was equal.
Integer[] myArray = ...;
assertThat(new HashSet(Arrays.asList(myArray)).size(), is(1));
Upvotes: 5