Java集合可以通過以下幾種方式實現去重:
List<String> list = new ArrayList<>();
list.add("apple");
list.add("banana");
list.add("apple");
Set<String> set = new HashSet<>(list);
System.out.println(set); // [apple, banana]
List<String> list = new ArrayList<>();
list.add("apple");
list.add("banana");
list.add("apple");
List<String> distinctList = list.stream().distinct().collect(Collectors.toList());
System.out.println(distinctList); // [apple, banana]
List<String> list = new ArrayList<>();
list.add("apple");
list.add("banana");
list.add("apple");
CollectionUtils.removeDuplicates(list);
System.out.println(list); // [apple, banana]