List<String> friends = new ArrayList<>();
friends.add("Raphael");
friends.add("Olivia");
friends.add("Thibaut");
List<String> friends = Arrays.asList("Raphael", "Olivia", "Thibaut");
Arrays.asSet()이 없음
Set<String> friends
= new HashSet<>(Arrays.asList("Raphael", "Olivia", "Thibaut"));
스트림 API 사용
Set<String> friends
= Stream.of("Raphael", "Olivia", "Thibaut")
.collect(Collectors.toSet());
⇒ 두 방법 모두 불필요한 객체 할당 필요로 함
⇒ 자바9에서는 작은 리스트, 집합, 맵을 쉽게 만들 수 있는 팩토리 메서드 제공
List.of() 메소드