import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public class GroupingCountingSortingAndStreams {
public static void main(String[] args) {
Arrays.asList("Lenin", "Kumar", "Koppoju", "Lenin", "Kumar")
.parallelStream()
.collect(
Collectors.groupingBy(
Function.identity(),
Collectors.counting()))
.entrySet()
.stream()
.sorted(
Map.Entry.<String, Long>comparingByValue()
.reversed()
.thenComparing(
Map.Entry.comparingByKey()))
.map(Map.Entry::getKey)
.limit(2)
.forEach(System.out::println);
}
}