• Post Reply Bookmark Topic Watch Topic
  • New Topic

Making Sure to Skip Duplicates When Populating LinkedList  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1739
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I make sure that the list 'rnameplates' does not get any duplicate values added to it?


 
Vasyl Lyashkevych
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in your condition you check only emply record


but there are not places where you can check instance into the list like something here:


More you can see here: http://stackoverflow.com/questions/30002483/arraylist-check-if-data-already-exists
 
Steve Dyke
Ranch Hand
Posts: 1739
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vasyl Lyashkevych wrote:

but there are not places where you can check instance into the list like something here:



That is what I thought I needed to do but I could not get following to work. Trying to iterate over the list as it is being built.

 
Campbell Ritchie
Sheriff
Posts: 53774
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use a List. Lists are designed to support duplicates, so you want a data structure that doesn't support duplicates. If you go through the Java™ Tutorials, you shou‍ld find a different sort of collection which both rejects duplicates and maintains insertion order. I regard it as a hybrid collection because it has features of two different types of collection.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!