0

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));
Lino
  • 19,604
  • 6
  • 47
  • 65
OTUser
  • 3,788
  • 19
  • 69
  • 127

1 Answers1

3
Map<UUID, String> collect = 
        List.of("john", "jack", "jill")
            .stream()
            .collect(Collectors.toMap(k -> UUID.randomUUID(), name -> name));
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Qmilogd
  • 56
  • 2
  • 1
    Hello! welcome to SO! Please add few lines of explanation of why the existing code does not work. What changes you have made and how does it fix the existing code. However small they are they will help the other people having the same problem. – Mritunjay Jan 17 '22 at 06:19