In java 8 , collect emp object based on some filter condition.
in main class
List empList = Arrays.asList(
new Emp(\"aaa\", languag
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());