Jeu de cordes avec Stream HashMap en Java 8

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 Stringdevrait être adopté à Collectors.toMap():

Map<String, List<String>> map = 
    mySet.stream()
         .collect(Collectors.toMap(Function.identity(),
                                   string -> {
                                       // put logic that returns List<String> here
                                   }));

Je suppose que tu aimes

Origine http://43.154.161.224:23101/article/api/json?id=187095&siteId=1
conseillé
Classement