allows me to enter the Id numbers without fear of duplication. my program should be able to display the list of ID numbers at the end
Asked
Active
Viewed 46 times
0
-
When you get a new value from the scanner, you need to check that it's not already added. How would YOU do this? – ControlAltDel Mar 01 '22 at 18:01
-
Does this answer your question? [How do I determine whether an array contains a particular value in Java?](https://stackoverflow.com/questions/1128723/how-do-i-determine-whether-an-array-contains-a-particular-value-in-java) – MarkusAnd Mar 01 '22 at 18:12
1 Answers
0
You're looking to use a HashSet
, which is built-in to Java. This is a datastructure which you can insert elements into, and also check if a certain element exists in constant time. Thus, when you read in an element, first check if the set contains said element; if so, skip it, otherwise, put it in your list of IDs and also insert it into your HashSet. You can see the documentation here

Jacob Steinebronn
- 833
- 3
- 12