Usage of new Collections factory methods introduced with Java 9

Initializing a Set

Set<String> countrySet = Set.of("France","Belgium","Germany");

Initializing a List

List<String> countryList = List.of("France","Belgium","Germany");

Initializing a Map

Map<String,String> countryCodeMap = Map.of("France","FR","United States","US","Canada","CA");

Subscribe to Java News and Posts. Get latest updates and posts on Java from
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus