Java tutorial
import java.util.Arrays; import java.util.Comparator; import java.util.List; public class Main { public static void main(String... args) { List<String> names2 = Arrays.asList("XML", null, "Java", "HTML", "CSS"); names2.sort(Comparator.nullsFirst(String::compareTo)); System.out.println(names2); } }