java ArrayList去重复值
2024-09-04 01:02:30
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;
}
最新文章
- 用字体在网页中画Icon图标
- 天书笔记:如何创建一个现代的footer(页脚)
- Spring3系列13-Controller和@RequestMapping
- Oracle性能优化--AUTOTRACE 操作
- 超级内存NVDIMM
- HTML页面背景音乐控制
- java单例模式使用及注意事项
- 《算法问题实战策略》-chaper15-计算几何-线段相交
- web文档类型DOCTYPE html很重要
- poj 1144 Network(割点)
- WinForm时间选择控件(DateTimePicker)如何选择(显示)时分秒
- flask请求上下文
- 【2016.3.16】作业 VS2015安装&;单元测试(1)
- oracle-表空间剩余空间大小占比查询
- 在ASP.NET MVC中使用Knockout实践07,自定义验证信息的位置与内容
- vue项目中遇到的一些问题
- GitBook入门(用github做出第一本书)——超详细配图说明
- springBoot单元测试-基础单元测试
- js时间对比-转化为几天前,几小时前,几分钟前
- Windows模拟linux终端工具Cmder+Gow