728x90
Map<Integer, Integer> map = new HashMap();
for (int i = 0; i < 10; i++) {
map.put(i, i);
}
Map<Integer, Integer> toMap = map.entrySet().stream()
.filter(m -> m.getKey() < 5)
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
System.out.println(toMap);
728x90
'Backend > Java' 카테고리의 다른 글
AutoBoxing과 AutoUnBoxing (0) | 2021.08.25 |
---|---|
@Async, CompletableFuture, parallelStream (0) | 2021.07.14 |
Collections.EMPTY_LIST, Collections.EMPTY_MAP (0) | 2021.07.12 |
jackson 역직렬화 시 주의할 점 (0) | 2021.04.14 |
ThreadLocal (0) | 2021.03.16 |