Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in arraylist

 
vijayz devraj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider a list with values
1
2
2
2
5
i need to retrieve data to check whether the data has duplicate or not by using hashcode.
can anyone suggest me through example. just need to diaplay amessage saying that ---yes the data inside has duplicate values
 
Manuel Leiria
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the contains() method in ArrayList
 
Rodrigo Tomita
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijayz,

I'm not exactly sure I got your question, however, keep in mind that Lists may contain duplicate values. On the other hand, Sets cannot contain duplicate values. Perhaps you can work with Sets if you don't want duplicate values (or copy the values to a Set and check its size compared to the List).

Regards.

Rodrigo
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure, but are you looking something like this:

This has int[] but you can have any other object and compare it accordingly..

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic