Published
- 1 min read
what are collectors in java
The solution for this is noted below
what are collectors in java
Solution
// Java program to implement the
// collectingAndThen() method
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class GFG {
public static void main(String[] args)
{
// Collects the elements and
// counts the occurrences
System.out.println(prepareTemperature()
.stream()
.collect(Collectors.groupingBy(
City::getName,
Collectors.collectingAndThen(
Collectors.counting(),
f -> f.intValue()))));
}
}
Try other methods by searching on the site. That is if this doesn’t work