如何删除ArrayList中的重复值? [重复]

问题描述 投票:-3回答:1

现在:

enter image description here

我想要:

enter image description here

码:

String[] contact = new String[contact_phoneList.size()];
for (int i = 0; i < contact_phoneList.size(); i++) {
    contact [i] = contact_phoneList.get(i);
}
java android contacts
1个回答
2
投票

使用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循环

© www.soinside.com 2019 - 2024. All rights reserved.