Streams – findAny() operation
Optional<T> findAny() class Test { public static void main(String[] args) { List<Integer> numbers = new ArrayList<>(Arrays.asList(3, 7, 9, 15, 17)); Optional<Integer> resultOptional = numbers.stream().findAny(); if (resultOptional.isPresent()) { // checking if optional contains any value System.out.println(“The element returned from the stream: ” + resultOptional.get()); // getting the value from Optional } else { System.out.println(“The stream is…
Read More Streams – findAny() operation