天天看点

list去重

Arraylist去除重复

//通过遍历老集合,把不包含的obj放到新集合里面去,产生一个新集合,就去重了

public static

ArrayListgetSingle(ArrayListlist){

ArrayList newArrayList =

new

ArrayList();

Iteratorit = list.iterator();

while

(it.hasNext()){

Object obj = it.next();

if

(!newArrayList.contains(obj)){

newArrayList.add(obj);

}

//产生的新的集合返回出去就是去重了

return

newArrayList;

继续阅读