• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to remove duplicate elements form an ArrayList?  RSS feed

 
Chan Apex
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please clear my doubt
thanks
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use any of the general algorithms available for identifying duplicate elements and then use the remove(int index) to remove the element. If you have tried out some code and are stuck do post it, we can help you out
 
Ed Ward
Ranch Hand
Posts: 147
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on the nature of the elements to be deduped and the context definition of "duplicate", you could just pass the List through a java.util.Set.
Short, simple, sweet.
 
Chan Apex
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes..we have to override equals() and hashCode() methods to remove dupicates in the Set..
 
Chan Apex
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Ed ward and Mohamed
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!