Java 11 Convert List of Strings to Map<UUID,String> [duplicate]
I am trying to convert the list of strings to Map as below but am getting a compilation error no instance(s) of type variable(s) K, T exist so that UUID conforms to Function<? super T, ? extends K>
, can someone please help me with it?
List.of("john","jack", "jill")
.stream()
.collect(Collectors.toMap(UUID.randomUUID(), name ->name));
Solution 1:
Map<UUID, String> collect =
List.of("john", "jack", "jill")
.stream()
.collect(Collectors.toMap(k -> UUID.randomUUID(), name -> name));