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   3711

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]    

 

Samsung to Shutdown Linux on Dex

Linux on DeX was based on Ubuntu and allowed you to create a full-fledged desktop when connecting a smartphone to a monitor
22 October 2019   77

Samsung has announced the closing out of its Linux on DeX environment testing program. Support for this environment for devices with firmware based on Android 10 will not be provided. Recall that the Linux on DeX environment was based on Ubuntu and allowed you to create a full-fledged desktop when connecting a smartphone to a stationary monitor, keyboard and mouse using the DeX adapter or when connecting a keyboard and mouse to a tablet.

Of the alternative projects with the implementation of portable Linux environments for smartphones that allow you to start the desktop when you connect a monitor to the smartphone via HDMI or using technologies such as Miracast and WiFi Display, we can mention: Maru OS, Complete Linux Installer, Linux Deploy, UserLAnd, AnLinux and GNURoot.