I have some exercises which in one tells me that giving a list which contains nulls, I must first sort it alphabetically and remove the nulls, I tried this since streams are required.
Stream<String> lista = Stream.of("p","a","b", null,"c", null,"b", null,"d","j", null,"z","x");
System.out.print("Lista en orden y sin nulos: El primero es ");
lista.sorted()
.filter(x -> x != null)
.forEach(x -> System.out.print(x));
As I have seen with that .filter
I should remove the nulls but when compiling it skips me:
Exception in thread "main" java.lang.NullPointerException.