I am trying to loop through my array and find all the numbers that are repeating more than once:
E.G: if there is 1 1 2 3 4
It should print saying \
I would use a HashMap
to store the value I encounter in the array, with the count as a value. So if you encounter a 4, you would look it up in the HashMap
, if it doesn't exist, you would add it with a value of 1, otherwise increment the value returned.
You can the loop over the HashMap
and get all the values and print the number of duplicates encountered in the array.