Filter based on condition and collect the object
You should not use flatMap
if you want to collect Emp
objects in the end because it will change every element to something else and it can be quite hard to map them back.
You should put all your logic in a filter
: "keep the Emp
object if getLanguage
contains "java"
".
empList.stream()
.filter(x->x.getLanguage().contains("java"))
.collect(Collectors.toList());