Karan
Karan

Reputation: 448

How to iterate over List<int[]> using Java 8 stream?

I have

List<int[]> allNumList = new ArrayList<>();

I am iterating over allNumList and matching one condition in below code .

for (int[] arr : allNumList) {
    for (int i : arr) {
        if (i == numb) {
            return false;
        }
    }
}

I want to do above code using Java 8.

Upvotes: 6

Views: 429

Answers (1)

Tomasz Linkowski
Tomasz Linkowski

Reputation: 4496

boolean noMatch = allNumList.stream()
    .flatMapToInt(Arrays::stream)
    .noneMatch(i -> i == numb);

Upvotes: 19

Related Questions