Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Making Sure to Skip Duplicates When Populating LinkedList  RSS feed

 
Ranch Hand
Posts: 1837
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?


 
Ranch Hand
Posts: 70
  • 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: 1837
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.

 
Marshal
Posts: 59131
180
  • 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.
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!