[Java] HashMap 정렬

호호빵·2022년 10월 30일
0

Java

목록 보기
11/19

람다식!


List<Map.Entry<String, Integer>> entryList = new LinkedList<>(scoreMap.entrySet());
        entryList.sort(new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o2.getValue() - o1.getValue();
            }
        });
       
        
List<Map.Entry<String, Integer>> entryList = new LinkedList<>(scoreMap.entrySet());
        entryList.sort(new Comparator<>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o2.getValue() - o1.getValue();
            }
        });

        
List<Map.Entry<String, Integer>> entryList = new LinkedList<>(scoreMap.entrySet());
        entryList.sort((o1, o2) -> o2.getValue() - o1.getValue());



        int minSize = Math.min(4,entryList.size()-1);
        for (int i = 0; i <= minSize; i++) {
            answer.add(entryList.get(i).getKey());
        }

HashMap 정렬하는 여러가지 방법

profile
하루에 한 개념씩

0개의 댓글

관련 채용 정보