Java9 has additional feature on Collections, based on requirement we need an immutable collections. To create immutable collections we can use of() method on Collection Class.
List<string> names = List.of("Jaya", "Kumar", "Reddy"); //Preserve the elements order System.out.println(names); //names.add("Brian"); //UnsupportedOperationException occurs //java.lang.NullPointerException //List<string> names2 = List.of("Jaya", "Kumar", "Reddy", null);
Set do not allow duplicate elements, where as list has duplicate elements.
Post a Comment
Post a Comment