• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unique elements in an array

 
Anurag Malaviya
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to count unique elements in an integer array without
using any predefined method?
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are lots of possible ways of doing that. What have you tried so far?
 
Anurag Malaviya
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic