如何去除 ArrayList 中的重复值?
How to remove Duplicate values in ArrayList?
现在:
我要:
代码:
String[] contact = new String[contact_phoneList.size()];
for (int i = 0; i < contact_phoneList.size(); i++) {
contact [i] = contact_phoneList.get(i);
}
使用HashSet删除重复值:
HashSet hs = new HashSet();
hs.addAll(contact_phoneList); // name of contact_phoneList from which you want to remove duplicates
contact_phoneList.clear();
contact_phoneList.addAll(hs);
不需要 for
循环
现在:
我要:
代码:
String[] contact = new String[contact_phoneList.size()];
for (int i = 0; i < contact_phoneList.size(); i++) {
contact [i] = contact_phoneList.get(i);
}
使用HashSet删除重复值:
HashSet hs = new HashSet();
hs.addAll(contact_phoneList); // name of contact_phoneList from which you want to remove duplicates
contact_phoneList.clear();
contact_phoneList.addAll(hs);
不需要 for
循环