Skip to main content
Active reading.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

In Java 9 we can easily initialize an ArrayList in a single line:

List<String> places = List.of("Buenos Aires", "Córdoba", "La Plata"); 

or

List<String> places = new ArrayList<>(List.of("Buenos Aires", "Córdoba", "La Plata")); 

This new approach of Java 9 has many advantages over the previous ones:

  1. Space Efficiency
  2. Immutability
  3. Thread Safe

See this post for more details -> What is the difference between List.of and Arrays.asList?What is the difference between List.of and Arrays.asList?

In Java 9 we can easily initialize an ArrayList in single line:

List<String> places = List.of("Buenos Aires", "Córdoba", "La Plata"); 

or

List<String> places = new ArrayList<>(List.of("Buenos Aires", "Córdoba", "La Plata")); 

This new approach of Java 9 has many advantages over the previous ones:

  1. Space Efficiency
  2. Immutability
  3. Thread Safe

See this post for more details -> What is the difference between List.of and Arrays.asList?

In Java 9 we can easily initialize an ArrayList in a single line:

List<String> places = List.of("Buenos Aires", "Córdoba", "La Plata"); 

or

List<String> places = new ArrayList<>(List.of("Buenos Aires", "Córdoba", "La Plata")); 

This new approach of Java 9 has many advantages over the previous ones:

  1. Space Efficiency
  2. Immutability
  3. Thread Safe

See this post for more details -> What is the difference between List.of and Arrays.asList?

Source Link
Mohit Tyagi
  • 2.9k
  • 4
  • 20
  • 30

In Java 9 we can easily initialize an ArrayList in single line:

List<String> places = List.of("Buenos Aires", "Córdoba", "La Plata"); 

or

List<String> places = new ArrayList<>(List.of("Buenos Aires", "Córdoba", "La Plata")); 

This new approach of Java 9 has many advantages over the previous ones:

  1. Space Efficiency
  2. Immutability
  3. Thread Safe

See this post for more details -> What is the difference between List.of and Arrays.asList?