aspose file tools*
The moose likes Java in General and the fly likes unique elements in an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "unique elements in an array" Watch "unique elements in an array" New topic
Author

unique elements in an array

Anurag Malaviya
Greenhorn

Joined: Jul 01, 2009
Posts: 19
how to count unique elements in an integer array without
using any predefined method?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4366
    
    8

There are lots of possible ways of doing that. What have you tried so far?
Anurag Malaviya
Greenhorn

Joined: Jul 01, 2009
Posts: 19
Matthew Brown wrote:There are lots of possible ways of doing that. What have you tried so far?


i am using a loop to traverse the array and find out the total number of occurrence of all elements .
But its not working properly. Can you suggest any other approach.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4366
    
    8

It's certainly possible that way - maybe you should show us your code and tell us what's not working. One thing - you might find it easier if you sort the array into ascending order first.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
Or copy the array and sort and search the copy.
Or copy all values into a set; adding values to a Set in Java™ gives a return value which might be helpful.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: unique elements in an array