Reputation: 1769
Consider a list of int[](in array).
Now I want to check the last element of the integer array be equal to 10. If any of the elments in the array is equal to 10 then I want to return true immediately. Else I want to return false.
This is my method to achieve this.
boolean checkList(List<int[]> attrList, Parent parent) {
for (int[] list : attrList)
{
if(parent.isAttributeEqualsTo10(list[list.length-1]))
return false;
}
return true;
}
Now How will I achieve this using Java 8 streams since we are iterating a collection.
Upvotes: 3
Views: 293
Reputation: 393781
Use anyMatch
:
return !attrList.stream().anyMatch (l -> parent.isAttributeEqualsTo10(l[l.length-1]));
Upvotes: 1