I need a data structure which works like the STL multiset but the TreeSet in Java doesn\'t allow duplicate elements. Is there any built-in data structure in Java which is eq
Algorithms 4th edition has a Bag implementation that's available on the book's web site. You can view the javadoc online as well.
The Bag class represents a bag (or multiset) of generic items. It supports insertion and iterating over the items in arbitrary order.
You'll probably just want to have a look at the source code if Bag is all you need, but there are a lot of other interesting things in algs4.jar, so it's worth a look.