Possible Duplicate:
Java – Distinct List of Objects
i have a sorted array of huge size (around 3000 strings) ,
i need to create an object for each distinct string ,
therefore i need create an array of objects with the size equal to distinct strings in the original array.
any suggestions?
Thanks
Well, if you need the distinct elements and not just the number, you may use a Set.
A Set is:
You keep adding your elements to the set, and then just look at what the set contains.
Something similar to this:
Usage:
Result:
Note that the order of the elements may not be preserved.
To find the number of the distinct elements, use: