Java集合去重復元素的方法有以下幾種:
List<String> list = new ArrayList<>(Arrays.asList("A", "B", "A", "C", "B"));
Set<String> set = new HashSet<>(list);
System.out.println(set); // 輸出:[A, B, C]
List<String> list = new ArrayList<>(Arrays.asList("A", "B", "A", "C", "B"));
Set<String> set = new LinkedHashSet<>(list);
System.out.println(set); // 輸出:[A, B, C]
List<String> list = new ArrayList<>(Arrays.asList("A", "B", "A", "C", "B"));
List<String> distinctList = list.stream().distinct().collect(Collectors.toList());
System.out.println(distinctList); // 輸出:[A, B, C]
List<String> list = new ArrayList<>(Arrays.asList("A", "B", "A", "C", "B"));
List<String> distinctList = new ArrayList<>(org.apache.commons.collections4.CollectionUtils.removeAll(list, null));
System.out.println(distinctList); // 輸出:[A, B, C]
以上是幾種常用的去除Java集合中重復元素的方法,根據具體情況選擇合適的方法即可。