Why doesn't the code below work? If Double replaced by Integer , then everything is OK. It seems that Collectors.toMap only accepts Integer as a key, any other type does not work ...

 List<Double> list1 = Arrays.asList(1.0, 2.0); List<String> list2 = Arrays.asList("one", "two"); Map<Double, String> map2 = list1.stream().collect(Collectors.toMap(list1::get, list2::get)); 
  • It seems that Collectors.toMap accepts only integers as a key - it is, but not Collectors.toMap, but List :: get - etki
  • Yes, exactly, rewrote in the following form, helped List <Integer> list0 = Arrays.asList (0, 1); List <Double> list1 = Arrays.asList (1.0, 2.0); List <String> list2 = Arrays.asList ("one", "two"); Map <Double, String> map2 = list0.stream (). Collect (Collectors.toMap (list1 :: get, list2 :: get)); - sva605

0