• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get Duplicate Objects from an ArrayList of Objects  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I get duplicates Objects from an ArrayList?


 
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A probably faster way is to use the containsAll() method but this method returns a boolean rather than a collection.

For non-duplicate Set works perfectly fine. You can do new HashSet<Order>(originalOrderList) instead of looping and checking.

 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Goutam reddy wrote:How can I get duplicates Objects from an ArrayList?

Without overriding the equals() and hashCode() methods in your Order class, the only time you will get a duplicate is if you are comparing an object with itself.
See the descriptions of those methods here for more details.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!