Java9: Collections Factory Methods
Java 9 comes with new factory methods to create collections easily.
Set<String> set = Set.of("A","B","C");
System.out.println(set);
List<String> list=List.of("A","B","C");
System.out.println(list);
Map<String,String> map=Map.of("A","Apple","B","Boy","C","Cat");
System.out.println(map);This of method allows initializing the collection in one go. Without this you will have to go through adding item one by one.
Get Nuwan Zen’s stories in your inbox
Join Medium for free to get updates from this writer.
Read my other blogs:







