Using Lambdas and Streams

    Sort a HashMap in Java - (4) Using the Stream API

    Using Lambdas and Streams Java 8 부터, map을 정렬하기 위해 Stream API 와 Lambda 표현식을 사용할 수 있다. map의 stream pipeline 에서 sorted 메서드만 호출하면 된다. 1. Key로 정렬 Key 값으로 정렬하기 위해 comparingByKey comparator 를 사용해야 한다. map.entrySet() .stream() .sorted(Map.Entry.comparingByKey()) .forEach(System.out::println); 적용 public class UsingStreamAPI { public static void main(String[] args) { Map map = new HashMap(); Employee empl..