一:

Hastset根据hashcode判断是否重复,数据不会重复

 Java代码 

  1. /** List order not maintained **/      
  2. public static void removeDuplicate(ArrayList arlList)      
  3. {      
  4. HashSet h = new HashSet(arlList);      
  5. arlList.clear();      
  6. arlList.addAll(h);      
  7. }     

二:

通过Hashset的add方法判断是否已经添加过相同的数据,如果已存在相同的数据则不添加

 

Java代码 
  1. /** List order maintained **/      
  2. public static void removeDuplicateWithOrder(ArrayList arlList)      
  3. {      
  4. Set set = new HashSet();      
  5. List newList = new ArrayList();      
  6. for (Iterator iter = arlList.iterator(); iter.hasNext(); )      
  7. {      
  8. Object element = iter.next();      
  9. if (set.add(element)) newList.add(element);      
  10. }      
  11. arlList.clear();      
  12. arlList.addAll(newList);      
  13. }    

 

 
以下来自网络:
 

方法一:循环元素删除 

java list 去除 重复值 //  删除ArrayList中重复元素 
}


方法二:通过HashSet剔除

java list 去除 重复值 //  删除ArrayList中重复元素 
}


方法三 删除ArrayList中重复元素,保持顺序

java list 去除 重复值 // 删除ArrayList中重复元素,保持顺序 
 }
 
自己使用: 删除 “0.0”的值
List<List<String>> list1 = (List<List<String>>) map.get("商品入库表"); //表1 入库详细表


//删除list中 数量为 0值
for (Iterator<List<String>> item = list1.iterator(); item.hasNext(); ) {
List<String> it = item.next();
System.out.print(it);
if (it.get(4).equals("0.0")) {
item.remove();
}
}
链接地址:http://iteye.blog.163.com/blog/static/186308096201302565345510/
 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2021-09-21
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2021-12-03
  • 2022-12-23
相关资源
相似解决方案