Friday 20 January 2012

Set With Cardinality



Java's Set interface  has 3  general purpose implementations,with differences in the purpose they serve (sorted,ordered,link mechanisms,bucketing formulae etc)


  1.HashSet
  2.TreeSet
  3.LinkedHashSet 


I was looking for some collection with  virtues like

  •  Indicating the collection has x number of  Y-type objects,n number of z-type objects.
  •  Remove n number of y-type objects from collection.
  •  Add 10 z-type objects to the collection etc
i.e collection which maintains some cardinality ,instead of just holding single instance of unique objects.
com.google.common.collect.HashMultiset Collection serves the purpose and it maintains the cardinality of the objects it is holding and the following is the simple block of code I've used to see how it works.






Thanks for reading.... cheers :-)


No comments:

Post a Comment