天天看點

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;

繼續閱讀