Differences between List.of and Arrays.asList in Java

Four main differences between List.of method, added in Java 9, and old one Arrays.asList 
31 October 2017   2135

In Java 9, there is new Collection Factory methods, called List.of:

List<String> strings = List.of("first", "second");

Let's figure out what's the difference between the previous and the new options.

There are 4 main differences:

Arrays.asList returns a mutable list while the list returned by List.of is immutable:

List<Integer> list = Arrays.asList(1, 2, null);
list.set(1, 10); // OK

List<Integer> list = List.of(1, 2, 3);
list.set(1, 10); // Fails

Arrays.asList allows null elements while List.of doesn't:

List<Integer> list = Arrays.asList(1, 2, null); // OK
List<Integer> list = List.of(1, 2, null); // Fails with a NullPointerException

contains method behaves differently with nulls:

List<Integer> list = Arrays.asList(1, 2, 3);
list.contains(null); // Return false

List<Integer> list = List.of(1, 2, 3);
list.contains(null); // Throws NullPointerException

Arrays.asList returns a view of the passed array, so the changes to the array will be reflected in the list too. For List.of this is not true:

Integer[] array = {1,2,3};
List<Integer> list = Arrays.asList(array);
array[1] = 10;
System.out.println(list); // Prints [1, 10, 3]

Integer[] array = {1,2,3};
List<Integer> list = List.of(array);
array[1] = 10;
System.out.println(list); // Prints [1, 2, 3]    


Microsoft to Use Chromium for Edge Browser

The company has already placed the repository on GitHub to attract new members to the development of the browser
07 December 2018   144

Microsoft Vice President Joe Belfiore said that from December 6, 2018, the company will use the Chromium engine in the Microsoft Edge browser. According to him, Microsoft also plans to develop browsers for smartphones and other devices.

The company has already placed the repository on GitHub to attract new members to the development of the browser. Microsoft expects that the transition to the new engine will be a big step in the development of Microsoft Edge. For example, the browser will finally be adapted for macOS.

According to Belfiore, the company plans to improve the project in three areas:

  • Users will get hardware integration, improved browser compatibility with sites and reduced power consumption of devices when using it.
  • Web developers will appreciate the reduced fragmentation of a web platform for testing sites.
  • The corporate IT sector will get the compatibility of old and new Windows applications that run in the browser.

He noted that during the year the company would work “under the hood” of Microsoft Edge, and named several key stages of this process. For example, the transition to a platform compatible with the Chromium engine for developing a desktop version of the browser. It is also planned that most platforms and all versions of Windows will support Microsoft Edge.