List 将重复数据排到一起,按原有List默认排序,不按hashCode排序
public static void main(String[] args) {
List<Integer> list = Arrays.asList(2, 3, 4, 1, 1, 2, 1);
Map<Integer, List<Integer>> map = list.stream().collect(Collectors.groupingBy(Function.identity(), LinkedHashMap::new, Collectors.toList()));
List<Integer> newList = Lists.newArrayList();
map.values().stream().forEach(groupList -> {
newList.addAll(groupList);
});
System.out.println(newList);
}