移除ArrayList内重复数据的两个方法
来源:互联网 发布:mac os 如何配置discuz 编辑:程序博客网 时间:2024/05/02 02:17
Expertise: Intermediate
Language: Java
Language: Java
Two Methods to Remove Duplicates in an ArrayList
Here are two methods that allow you to remove duplicates in an ArrayList. removeDuplicate does not maintain the order where as removeDuplicateWithOrder maintains the order with some performance overhead.
1.The removeDuplicate Method: /** List order not maintained **/
public static void removeDuplicate(ArrayList arlList)
{
HashSet h = new HashSet(arlList);
arlList.clear();
arlList.addAll(h);
}
2.The removeDuplicateWithOrder Method:
/** 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);
}
Vijayanandraj Amaladoss
- 移除ArrayList内重复数据的两个方法
- 移除ArrayList内重复数据的两个方法
- 移除ArrayList集合中重复的元素
- 两个ArrayList合并,并且去掉重复数据的算法
- java两个ArrayList合并,并且去掉重复数据的算法
- 两个ArrayList合并,并且去掉重复数据的算法
- 移除ArrayList中的重复值
- 移除ArrayList中的重复元素
- UNIX下去除文件中重复数据的方法
- 用Arraylist的contains()方法去掉文件中的重复数据
- 去除重复的Arraylist数据
- 去除重复的Arraylist数据
- 移除重复数据并插入置顶的文章ID
- C#返回arraylist集合长度的方法是什么?C#ArrayList重复数据删除
- Java学习笔记---实现两个ArrayList合并,并去掉重复数据的算法
- C# 移除数组中重复数据
- SQL除重复数据
- SQL两个表连接查询去掉重复数据的方法
- 为Web应用建立JMX管理系统(一)
- 十五位的身份证号转为十八位的
- 写给自己的一些话
- 今天申请回公司
- MD5算法说明
- 移除ArrayList内重复数据的两个方法
- 中国企业实施ERP之难点全攻略
- OnDraw中画三角形和矩形的VC代码
- 关于JAVA的分页查询操作技术
- O/R Mapping 在.NET下的应用那位比较熟啊,请给点建议
- 我的座佑铭,大家共勉
- 无视挫折,勇于向前
- 1997年欧洲编程高手一等奖
- 为Web应用建立JMX管理系统(二)