0 votes
in JAVA by
How to check if list is empty in Java 8 using Optional, if not null iterate through the list and print the object?

1 Answer

0 votes
by
Optional.ofNullable(noteLst)
            .orElseGet(Collections::emptyList) // creates empty immutable list: [] in case noteLst is null
            .stream().filter(Objects::nonNull) //loop throgh each object and consider non null objects
            .map(note -> Notes::getTagName) // method reference, consider only tag name
            .forEach(System.out::println); // it will print tag names

Related questions

0 votes
asked Apr 26 in JAVA by SakshiSharma
0 votes
0 votes
asked Jun 22, 2019 in PHP by SakshiSharma
...