I have the following Java code snippet:
Map<String, List<String>> phones = new HashMap<>();
phones.put("User1", Arrays.asList("0502324547", "0651634767"));
phones.put("User2", Arrays.asList("0977634321", "0697654221"));
phones.put("User3", Collections.singletonList("0970011223"));
Map<String, String> map = phones
.entrySet()
.stream()
.flatMap(e -> e.getValue().stream().map(v -> new AbstractMap.SimpleEntry<>(v, e.getKey())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Using it I'm converting
Map<String, List <String>>
to
Map<String, String>
and then passing to the method like:
public Map<String, List<String>> createNotebook(Map<String, String> phones) {
Map<String, List<String>> collectionsMap = new HashMap<>();
// here I want to convert vice versa
return collectionsMap;
}
Can I do similar to this, but vice versa?