InterviewSolution
Saved Bookmarks
| 1. |
Why were Streams introduced in Java 8? |
|
Answer» STREAMS support aggregate operations and introduced in JAVA 8. It is a sequence of OBJECTS with operations like Sorted, Map, Filter, etc. For Streams, the following package is used: import java.util.STREAM.*;Here is an example of Stream operations in Java 8 to work with map and collect: import java.util.*; import java.util.stream.*; public class Demo { public static void main(String args[]) { List<Integer> L = Arrays.asList(29, 35, 67); List<Integer> res = l.stream().map(a -> a*a).collect(Collectors.toList()); System.out.println(res); } } |
|