【问题标题】:How to remove Duplicate values in ArrayList? [duplicate]如何删除 ArrayList 中的重复值? [复制]
【发布时间】:2019-02-23 08:54:54
【问题描述】:

现在:

我想要:

代码:

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】:

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

【讨论】:

  • 成功了。太感谢了。你是最棒的^^
  • 欢迎......:)
猜你喜欢
  • 2013-09-04
  • 2010-12-25
  • 2014-03-25
  • 2020-03-06
  • 2016-01-12
  • 2018-05-29
  • 2016-07-08
  • 1970-01-01
  • 2013-04-10
相关资源
最近更新 更多