java ArrayList去重复值
Posted Debugs
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java ArrayList去重复值相关的知识,希望对你有一定的参考价值。
public static List removeDuplicateWithOrder(List list) {
Set set = new HashSet();
List newList = new ArrayList();
for (Iterator iter = list.iterator(); iter.hasNext();) {
Object element = iter.next();
if (set.add(element)){
newList.add(element);
}
}
return newList;
}
------
public static List removeDuplicateWithOrder(List list) {
Set set = new HashSet(list.size());
set.addAll(list);
List newList = new ArrayList(set.size());
newList.addAll(set);
return newList;
}
----
public static List removeDuplicateWithOrder(List list) {
List newList = new ArrayList();
for (Object o : list) {
if (!newList .contains(o)) newList.add(o);
}
return newList;
}
以上是关于java ArrayList去重复值的主要内容,如果未能解决你的问题,请参考以下文章