package StreamShortCircuitOperations; import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; import StudentClass.Student; public class FindAnyOperation { public static void main(String[] args) { Stream stream = Stream.of(new Student(1,"Ram"),new Student(2,"Arjun"),new Student(3,"Kavi"),new Student(4,"Sanju"),new Student(5,"Ajay")); List list = new ArrayList<>(); stream.forEach(e->list.add(e.getName())); //get & store in a string and print value String firstMatchedName = list.stream().filter((s) -> s.startsWith("A")).findAny().get(); System.out.println(firstMatchedName); //Sequential Stream - returns first element Stream stream1 = list.stream(); stream1.findAny().ifPresent(System.out::println); //Parallel stream -> returns random element Stream stream2 = list.stream(); stream2.parallel().findAny().ifPresent(System.out::println); } }