how to check if all elements of java collection match some condition? -
i have arraylist<integer>. want check if elements of list greater or less condition. can iterating on each element. want know if there method in collection class reply can find maximum or minimum collections.max() , collections.min() respectively.
if have java 8, utilize stream's allmatch function (reference):
arraylist<integer> col = ...; col.stream().allmatch(i -> i>0); //for illustration integers bigger 0 java collections
No comments:
Post a Comment