Iterate through ArrayList with If condition and return boolean flag with stream api

Suule :

I am trying to make myself more comfortable with Java 8 Stream api. Currently I want to translate something like as stream, but it seems I am still not comfortable enough, because I have no idea how to do this.

boolean isTrue = false;

for (Integer integer : intList) {
    if (integer > 10) {
        isTrue = true;
        break;
    }
}
Eugene :

All you care about is if at least one input from your list is bigger than 10, thus anyMatch:

boolean isTrue = intList.stream()
                        .anyMatch(x -> x > 10);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=110859&siteId=1