Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Iterating over a list - Java

 
Grishma Dube
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say that your list is defined as :



Use the following code :



Good luck ...
 
Paul Clapham
Sheriff
Posts: 21316
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I learnt from this topic as well

Thanks ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic