常见写法:
List<Integer> deployProcess = service.getDeployProcess(xxx);
List<Integer> newList = new ArrayList<>(deployProcess.size());
deployProcess.forEach(i -> {
if (!newList.contains(i)) { // 如果新集合中不存在则插入
newList.add(i);
}
});
System.out.println("去重后的新集合:" + newList);
可修改为利用java8新特性中的stream,进行便捷去重:
List<Integer> deployProcess = service.getDeployProcess(xxx);
deployProcess = deployProcess.stream().distinct().collect(Collectors.toList());