1.set
ArrayList<Object> objects=new ArrayList<>(new HashSet<>(list))
2.list.contain
List<String> testListDistinctResult = new ArrayList<>();
for (String str : testList) {
if (!testListDistinctResult.contains(str)) {
testListDistinctResult.add(str);
}
}
3.stream.distinct
List<String>testListDistinctResult=testList.stream().distinct().collect(Collectors.toList());
4.双重for循环
for (int i = 0; i < testList.size(); i++) {
for (int j = i + 1; j < testList.size(); j++) {
if (testList.get(i).equals(testList.get(j))) {
testList.remove(j);
}
}
}