I have a simple array with ten integer values. I can get the 'for' loop to count the total number of values in the array, the maximum etc, but how do I get it to calculate the total number of unique/distinct values in the array.
My current code is as follows,
This code calculates the maximum value in the array. Any idea how to change this?
On the same path, but with little difference, when u add a member from the Array to your hasmap u can verify with containsKey() method of HashMap. If u get true then move on to Next element in Array, other wise add a member from array to HashMap.
At the end HashMap.size() and u can find the total number of unique member in your array.
This way it mightget improve the performance
Always code as if person who is going to maintain your code is a maniac serial killer and knows where you live
posted 14 years ago
Thanks for the replies. Have a great week.
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop