I feel embarrassed that I am stuck on this but I am trying to pull the List of Strings (List<String>
) from the Map<MyEnum, String>
given then List of enum keys List<MyEnum>
. The List<MyEnum>
may or may not contain entries.
Edit:
List<String> toReturn = new ArrayList<>();
for (MyEnum field : fields) {
String value = null;
if ((value = map.get(field)) != null) {
toReturn.add(value);
}
}
return toReturn;
But I am looking for a Java 8 way to do this. Such as...
map.stream().map(e->?????)
fields.stream()
.map(map::get)
.filter(Objects::nonNull)
.collect(Collectors.toList())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With