Cod sursa(job #2191522)

Utilizator ibicecIT Zilla ibicec Data 2 aprilie 2018 22:25:32
Problema Hashuri Scor 0
Compilator java Status done
Runda Arhiva educationala Marime 0.96 kb
package org.iuliu;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {

        List<String> colors = Arrays.asList("Red", "Green", "Blue", "Red", "Yellow", "Green");

        Map<String, Long> colorCount = colors.stream().collect(
                Collectors.groupingBy(Function.identity(), Collectors.counting())
        );

        List<Map.Entry<String, Long>> sortedColorGroups = colorCount.entrySet().stream().sorted(
                Comparator.comparing((Function<Map.Entry<String, Long>, Long>) Map.Entry::getValue).reversed().thenComparing(
                        Comparator.comparing(Map.Entry::getKey)
                )
        ).collect(Collectors.toCollection(LinkedList::new));

        sortedColorGroups.forEach(
                colorEntry -> System.out.println(colorEntry.getKey() + " " + colorEntry.getValue())
        );

        // write your code here
    }
}