I have a map as below
Map<String, String> myMap = new HashMap<>();
myMap.put("a", "Something");
myMap.put("b", null);
myMap.put("c", "more");
and a list,
List<String> myList = Arrays.asList("a","b");
I want to check, whether all the values in myMap with keys in myList are null
I have created a method as follows and it works fine. I wanted to check whether we can achieve the same in one line of code using stream
myMap.values().removeIf(Objects::isNull);
Map<String, String> resultMap = myList.stream().filter(myMap::containsKey).collect(Collectors.toMap(Function.identity(), myMap::get));
if(!resultMap.isEmpty()){
// Atleast one not null value is present in myMap with key in myList
}