Java 8 如何使用Java8将ArrayList转换为映射?
我有以下要求,我想使用Java-8来满足所需的解决方案: 输入->Java 8 如何使用Java8将ArrayList转换为映射?,java-8,Java 8,我有以下要求,我想使用Java-8来满足所需的解决方案: 输入-> ArrayList<String> places = new ArrayList<String>( Arrays.asList("Buenos Aires", "Córdoba", "La Plata", "Paris")); 如何使用Java-8实现这一点?以下是使用流实现这一点的方法 List<String
ArrayList<String> places = new ArrayList<String>(
Arrays.asList("Buenos Aires", "Córdoba", "La Plata", "Paris"));
如何使用Java-8实现这一点?以下是使用流实现这一点的方法
List<String> places = Arrays.asList("Buenos Aires", "Córdoba", "La Plata", "Paris");
Map<String, List<String>> map = places.stream().collect(Collectors.toMap(Function.identity(), e-> places.stream().filter(k -> !e.equals(k)).collect(Collectors.toList())));
List places=Arrays.asList(“布宜诺斯艾利斯”、“科尔多瓦”、“拉普拉塔”、“巴黎”);
Map Map=places.stream().collect(Collectors.toMap(Function.identity(),e->places.stream().filter(k->!e.equals(k)).collector(Collectors.toList());
List<String> places = Arrays.asList("Buenos Aires", "Córdoba", "La Plata", "Paris");
Map<String, List<String>> map = places.stream().collect(Collectors.toMap(Function.identity(), e-> places.stream().filter(k -> !e.equals(k)).collect(Collectors.toList())));