如何从ARRAYLIST中删除重复的值 [英] how to remove duplicate value from ARRAYLIST
本文介绍了如何从ARRAYLIST中删除重复的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我有一个arraylist,其中包含来自不同数据库的值,但是它存储了一些重复的值,因此,我想删除重复的值并仅将唯一值存储在ARRay列表中.
那么,这怎么可以实现呢?
在此先感谢...
Mitesh
hello,
i have one arraylist wich contain values from different database but it stores some duplicate values so, i want to remove duplicate values and store only unique value in ARRay List.
So, how can this is achievable ?
Thanks in Advance...
Mitesh
推荐答案
您可以使用临时容器(例如HashSet)并将所有元素添加到其中.最后,将HashSet的数据复制到ArrayList.
干杯..
You can use a temporary container such as HashSet and adding all element to it. Finally copy the data of HashSet to ArrayList.
Cheers..
ArrayList ar = new ArrayList();
for (int h = 0; h<ds1.Tables[0].Rows.Count; h++)
{
if (!ar.Contains(ds1.Tables[0].Rows[h][0].ToString()))
{
ar.Add(Convert.ToString(ds1.Tables[0].Rows[h][0].ToString()));
}
}
这篇关于如何从ARRAYLIST中删除重复的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文