2017-11-20 3 views

답변

8

Map의 항목을 필터링하여 값에 "문자열"키가 들어있는 항목 만 유지할 수 있습니다. 그런 다음 새로운 Map로를 수집하는 Collectors.toMap를 사용

Map<Key1, CustomObject> map = 
    inputMap.entrySet() 
      .stream() 
      .filter(e -> e.getValue().containsKey("a string")) 
      .collect(Collectors.toMap(Map.Entry::getKey, 
             e -> e.getValue().get("a string"))); 
+0

예, 작동합니다. 감사합니다. D –

0

또한

Map<String, SocialCredentials> collect = configData.getData() 
       .entrySet().stream() 
       .map(map -> map.getValue() 
         .entrySet().stream() 
         .filter(entry -> 
          profile.toLowerCase().equals(entry.getKey())) 
         .collect(Collectors.toMap(p -> map.getKey(), 
                Map.Entry::getValue))) 
       .collect(HashMap::new, Map::putAll, Map::putAll); 

를 작동하지만 솔루션은 내 경우에는 더 적합합니다.