I have a code as following :
List<UserDTO> result = new ArrayList<>();
UserDTO userDTO;
for (User user : users) {
for (Individual individual : individuals) {
if (individual.getKey().equals(user.getIndividualId())) {
userDTO = new UserDTO();
userDTO.setUserId(user.getUserId());
userDTO.setFirstName(individual.getFirstName());
userDTO.setLastName(individual.getLastName());
result.add(utilisateurDTO);
break;
}
}
}
How can I write this using Java 8 streams ?
HashMapand then iterate over the other, looking up the corresponding entry in the map. Also, you are expected to make an attempt, we are not going to write the code for you. Try it and ask a specific question when you run into an issue. Please visit the help center, take the tour end read How to Askresultas anArrayList. Also, any attempt you can include in your questions can help us determine where you're stuck.