• Post Reply Bookmark Topic Watch Topic
  • New Topic

Counting the number of occurences in a data structure  RSS feed

 
Allen Bandela
Ranch Hand
Posts: 128
Eclipse IDE MS IE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering if there was any data structure that has a method that could count the number of occurences of an element within it.
For example: I wanted to rank a set of elements by their occurence in a list.
I could do it with a couple of for loops checking if that element occured before. But, I want to do it the most efficient and less time consuming way. If anyone has any ideas . Thanks
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you want is a Bag. Jakarta Commons Collections has implementations for this datastructure, for example:

http://jakarta.apache.org/commons/collections/apidocs/org/apache/commons/collections/bag/HashBag.html
 
Allen Bandela
Ranch Hand
Posts: 128
Eclipse IDE MS IE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ilja. How you doing man? Have a good one.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!