Julez :
Comment puis-je créer HashMap String et liste de chaînes de Jeu de cordes avec Stream?
Set<String> mySet;
Map<String, List<String>> = mySet.stream().map(string -> {
// string will be my key
// I have here codes that return List<String>
// what to return here?
}).collect(Collectors.toMap(.....)); // what codes needed here?
Je vous remercie.
Ils étaient les suivants:
Vous n'avez pas besoin de l' map()
étape. La logique qui produit un à List<String>
partir d' un String
devrait être adopté à Collectors.toMap()
:
Map<String, List<String>> map =
mySet.stream()
.collect(Collectors.toMap(Function.identity(),
string -> {
// put logic that returns List<String> here
}));