[Java] HashMap key, value 정렬


[Java] HashMap key, value 정렬

import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Map<Integer, Integer> map = new HashMap<>(); map.put(4, 1); map.put(3, 2); map.put(5, 3); map.put(1, 4); map.put(8, 5); map.put(7, 6); map.put(2, 7); map.put(6, 8); List<Integer> klist = new ArrayList<>(map.keySet()); // key 정렬 Collections.sort(klist); // key 기준 오름차순 정렬 Collections.sort(klist, Collections.reverseOrder()); // key 기준 내림차순 정렬 // value 정렬 Collections.sort(klist, (k1,...


#HashMap #Java #key정렬 #Map #Map정렬 #value정렬 #자바

원문링크 : [Java] HashMap key, value 정렬