Posts

Showing posts with the label Java 9 - Collection factory methods

Java 9 - Collection Factory methods

Image
Hi, I am Malathi Boggavarapu working at Volvo Group and i live in Gothenburg, Sweden. I have been working on Java since several years and had vast experience and knowledge across various technologies. Let's jump start into Java 9 features Collection Factory methods Java9 provides some collection factory methods for creating List, Set and Map in more convenient way. Collections: The traditional way 1) Here we use many lines of code to create a small immutable collection of List of books. It is very verbose using the traditional way. List<String> books = new ArrayList<String>(); books.add("Java 9"); books.add("Java 8"); books.add("Java 7"); books.add("Java 6"); 2) There is one more way to create a list of books. We can use Arrays class to create a List.  List<String> books = Arrays.asList("Java 9 Modularity", ..); It's bit weird that you do it using Arrays class. Is ...