一:
Hastset根據hashcode判斷是否重複,資料不會重複
Java
{ HashSet h = new HashSet (arlList); arlList.clear(); arlList.addAll(h); 過相同的數據,如果已存在相同的數據則不加入Java程式碼/** List order maintained **/ public static void removeDuplicateWithOrder(ArrayList arlList) { Set set = new HashSet(); List newList = new ArrayList(); for (Iterator iter = arlList.iterator(); iter.hasNext(); ) { Object element = iter.next(); if (set.add(element)) newList.add(element); } arlList.clear(); arlList.addAll(newList); }以下來自網路: 方法一:循環元素刪除
// 删除ArrayList中重复元素 public static void removeDuplicate(List list) { for ( int i = 0 ; i < list.size() - 1 ; i ++ ) { for ( int j = list.size() - 1 ; j > i; j -- ) { if (list.get(j).equals(list.get(i))) { list.remove(j); } } } System.out.println(list); }方法二:透過HashSetp
rr,剔除順序連結網址:http://iteye.blog.163.com/blog/static/186308096201302565345510/