wood burning stoves*
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
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: 4392
    
    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: 4392
    
    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: 38881
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unique elements in an array