wood burning stoves 2.0*
The moose likes Java in General and the fly likes Iterating over a list - Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Iterating over a list - Java" Watch "Iterating over a list - Java" New topic
Author

Iterating over a list - Java

Grishma Dube
Ranch Hand

Joined: Jul 01, 2003
Posts: 275
Hi,

I have got a list of accounts. There can be more than one record of one single account in the list.

Out of this list i need to prepare a list, which will have only one record of an account. In shotr i want to remove duplicate record.

Please give me some idea, how should i iterate the list.

Thanks
Grishma
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
Let's say that your list is defined as :



Use the following code :



Good luck ...


Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You shouldn't iterate the list. This filters out the duplicates for you:That's assuming you have an equals() method that returns true if two accounts are the same. And if you want to preserve the sequence of the original list then use a LinkedHashset.
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
I learnt from this topic as well

Thanks ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Iterating over a list - Java