Java / Java8 streams
Write a Java8 program to remove null from a stream.
Refer the below program.
import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; public class FilterNull { public static void main(String[] args) { Stream<String> streamOfStrings = Stream.of("One", "Two", "Three", null, "Five", null); List<String> notEmptyStrings = streamOfStrings.filter(x -> x != null).collect(Collectors.toList()); notEmptyStrings.forEach(System.out::println); } }
More Related questions...