Java / Java8 streams
Explain the Collectors framework in Java8.
Java 8 Collectors main components are,
- Stream.collect() method,
- Collector interface,
- and Collectors class.
collect() method, a terminal operation in Stream interface, is a special case of reduction operation called mutable reduction operation because it returns mutable result container such as List, Set or Map according to supplied Collector.
java.util.stream.Collector interface contains functions that work together to accumulate input elements into a mutable result container.
java.util.stream.Collectors class contains static factory methods that perform some common reduction operations such as accumulating elements into Collection, finding min, max, average, the sum of elements, etc. All the methods of Collectors class return Collector type which will be supplied to collect() method as an argument.
List<String> empNameList = employeeList.stream().map(emp-> emp.getName()).collect(Collectors.toList());
More Related questions...