import java.util.Comparator; import java.util.List; import java.util.Optional; public class Main { public static void main(String... args) { List<String> names3 = null; Optional.ofNullable(names3).ifPresent(list -> list.sort(Comparator.naturalOrder())); System.out.println(names3); } }