Hello Everyone, Can anyone explain to me what is a Stream? How does It differ from a collection? Actually, I am preparing some topics for the java 8 interview and I have doubts regarding this. If anyone knows please suggest me.
A stream represents a sequence of elements and supports different kind of operations to perform computations upon those elements:
List<String> myList =
Arrays.asList("a1", "a2", "b1", "c2", "c1");
myList
.stream()
.filter(s -> s.startsWith("c"))
.map(String::toUpperCase)
.sorted()
.forEach(System.out::println);
// C1
// C2