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));