0

I am trying to keep all entries in the Map where the key is in the list of Strings. This is what I have:

List<String> outputKeys = Arrays.asList("key1", "key2", "key3");
foo = map.entrySet()
         .stream()
         .filter(p -> outputKeys.contains(p.getKey()))
         .collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue()));

There are compilation errors at p.getKey() and p.getValue():

Error:(151, 75) java: cannot find symbol
symbol:   method getKey()
location: variable p of type java.lang.Object
WoLfPwNeR
  • 1,148
  • 4
  • 11
  • 27

0 Answers0