728x90
Inner Join
Map<Long, User> userIdMap = userList.stream()
.collect(Collectors.toMap(User::getUserId, Function.identity()));
List<Pair<Order, User,>> innerJoinList = orderList.stream()
.filter(it -> userIdMap.containsKey(it.getUserId()))
.map(it -> Pair.of(it, userIdMap.get(it.getUserId())))
.collect(Collectors.toList());
Left Join
Map<Long, Order> orderIdMap = orderList.stream()
.collect(Collectors.toMap(Order::getUserId, Function.identity()));
List<User> leftJoinUser = userList.stream()
.filter(it -> !orderIdMap.containsKey(it.getUserId()))
.collect(Collectors.toList());
'JAVA' 카테고리의 다른 글
Google Java Style Guide (0) | 2022.09.14 |
---|---|
spring boot async 비동기 병렬처리 (0) | 2022.06.22 |
JVM 구조 (0) | 2022.03.06 |
java optional (0) | 2022.01.12 |
java Stream (0) | 2022.01.12 |