1.基于HashSet里面的元素不可重复
public class QuChong {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("a");
arrayList.add("a");
arrayList.add("c");
arrayList.add("c");
arrayList.add("e");
arrayList.add("e");
System.out.println(arrayList);
arrayList = new ArrayList<>(new HashSet<>(arrayList));
for (int i = 0; i < arrayList.size(); i++) {
System.out.println(("arrayList [" + i + "] = " + arrayList.get(i)));
}
}
}
|
|