我建议创建一个
HashMap<String, List<List<String>>>
,并将这些列表分组。那就打电话
map.values()
得到
Collection<List<List<String>>>
.
List<List<String>> list = new ArrayList<>();
list.add(Lists.newArrayList("A", "B", "Y"));
list.add(Lists.newArrayList("C", "D", "Z"));
list.add(Lists.newArrayList("A", "D", "X"));
list.add(Lists.newArrayList("D", "C", "A"));
Map<String, List<List<String>>> mapped = list.stream()
.collect(Collectors.groupingBy(li -> li.get(1)));
System.out.println(mapped);
Collection<List<List<String>>> groupedList = mapped.values();