how can i check if the elements in an array exist twice
you already opened this thread under "checkNonDuplicates", and you got the answer there. Why are you asking again? If the answer I (and others ) gave is not fitting, then rephrase your question more specific, and tell me why the aswer is not sufficient or what you did not understand.
Quotation from my answer:
Otherwise, to sort out the duplicates in an array that already contains random generated numbers, you have to compare the last number in array against all the others and delete if it already exists, then the second last against all the others and so on. (like bubble sort).
or you use a Binary Tree for better performance: put the first in, then the second if the second is not already inside, then the third if it is not already inside and so on.
there is also another idea: it's not so fast, but easier to program for you,because it does not need a double-for-loop.
Just convert the number to a string.
start with:
- Properties properties= new Properties();
then use a simple for-loop to loop through all the numbers and use
- properties.setProperty(currentNumberAsString, "dummyValue")
.
At the end, you can get all numbers back with "properties.propertyNames()".
You will see that there are no duplicates among them.