June 2018
Beginner
722 pages
18h 47m
English
The following Terminal operations allow us to find any, or the first, element of the stream:
The following example illustrates these operations:
List<String> list = List.of("1", "2", "3", "4", "5");Optional<String> result = list.stream().findAny();System.out.println(result.isPresent()); //prints: trueSystem.out.println(result.get()); //prints: 1result = list.stream().filter(e -> "42".equals(e)).findAny();System.out.println(result.isPresent()); //prints: ...
Read now
Unlock full access