File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unique elements in an array

 
Anurag Malaviya
Greenhorn
Posts: 19
  • 0
  • 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: 4549
8
Java Netbeans IDE Scala
  • 0
  • 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
  • 0
  • 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: 4549
8
Java Netbeans IDE Scala
  • 0
  • 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
Pie
Posts: 47229
52
  • 0
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic