在Arraylist中重复 [英] Duplicates in Arraylist

查看:70
本文介绍了在Arraylist中重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从arraylist中删除重复项?

How do I remove duplicates from an arraylist?

推荐答案

一个******* @ discuss.microsoft.com 写道:
如何从arraylist中删除重复项?
How do I remove duplicates from an arraylist?




如果首先对列表进行排序没问题,可以用一个循环来完成

(代码在VB.NET中):


arr.Sort()

Dim count As Integer = arr.Count

Dim i As Integer

对于i = count - 1到1步-1

If(arr(i).ToString()= arr(i - 1).ToString())然后

arr.RemoveAt(i)

结束如果

下一页我


-


Edge



If it''s no problem to sort the list first, you can do it with a single loop
(code is in VB.NET):

arr.Sort()
Dim count As Integer = arr.Count
Dim i As Integer
For i = count - 1 To 1 Step -1
If (arr(i).ToString() = arr(i - 1).ToString()) Then
arr.RemoveAt(i)
End If
Next i

--

Edge





只需循环,然后测试它到同一个arraylist后启动测试索引

您正在测试的那个,当发现一个平等时,将所有项目移动一个

项目从t开始之后他找到一个并删除了最后一项。并且

只有在没有平等时才进入下一个。


在我看来非常简单。


我希望这有帮助吗?


Cor
Hi,

Just looping, testing it to the same arraylist starting the test index after
the one you are testing and when found an equality move all items up one
item from starting one after the found one and remove the last item. And
proceed to the next one only when there has been no equality.

Very simple in my opinion.

I hope this helps?

Cor





看见来自Ed的解决方案,在我的文本中向上移动当然是疯狂的,当你移除时,自动地转到




在我的文本中我试图避免排序,这取决于你


Cor
Hi,

Seeing the solution from Ed, moving up is of course crazy in my text, goes
automaticly when you removeat.

And in my text I tried to avoid the sort so that is up to you

Cor


这篇关于在Arraylist中重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆