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

后端 未结 7 625
灰色年华
灰色年华 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:50

    TreeSet set = new TreeSet<>();
    TreeSet multiset = new TreeSet<>((i, j) -> i < j ? 1 : -1);
    

    Make a set multiset just by making 1 != 1!

提交回复
热议问题