Does Java have a multiset data structure like the one in C++ STL?

后端 未结 7 633
灰色年华
灰色年华 2020-12-28 13:00

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

7条回答
  •  忘掉有多难
    2020-12-28 13:36

    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.

提交回复
热议问题