In java 8 , collect emp object based on some filter condition.
in main class
List empList = Arrays.asList(
new Emp(\"aaa\", languag
You can also do like this.
List<Object> optionMetas = new ArrayList<>();
Map<Long, Object> optionIdMetaMap_ = optionMetas.stream().filter(option -> option.getXX() || option.getXXX().equal("java"))
.collect(Collectors.toMap(Object::getKEY, item-> item));
Add your relevant condition in filter()
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());