나는 Map<Key1, Map<Key2, CustomObject>>
입니다. Map
을 통과해야하고 Key2.equals("a string")
을 확인하고 Map<Key1, CustomObject>
을 반환해야합니다.Java 8을 사용하여 String Map과 Map Map을 스트리밍 할 수 있습니까?
java 8에서도 가능합니까? 자바 8로 끝내야할까요, 아니면 중첩 된 루프로 더 좋을까요?
나는 Map<Key1, Map<Key2, CustomObject>>
입니다. Map
을 통과해야하고 Key2.equals("a string")
을 확인하고 Map<Key1, CustomObject>
을 반환해야합니다.Java 8을 사용하여 String Map과 Map Map을 스트리밍 할 수 있습니까?
java 8에서도 가능합니까? 자바 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")));
또한
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);
를 작동하지만 솔루션은 내 경우에는 더 적합합니다.
예, 작동합니다. 감사합니다. D –