[Solved] Java 8 – collecting into a map from a list of objects with nested list
[ad_1] Assuming you want a Map<User.userId, List<UserData.customerId>> you can use this: Map<Long, List<Long>> result = users.stream() .collect(Collectors.toMap( User::getUserId, u -> u.getUserData().stream() .map(UserData::getCustomerId) .collect(Collectors.toList()) )); 3 [ad_2] solved Java 8 – collecting into a map from a list of objects with nested list