A TreeSet or TreeMap that allow duplicates

前端 未结 7 1751
走了就别回头了
走了就别回头了 2021-01-17 23:12

I need a Collection that sorts the element, but does not removes the duplicates.

I have gone for a TreeSet, since TreeSet actu

7条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-18 00:00

    You can use a PriorityQueue.

    PriorityQueue pQueue = new PriorityQueue(); 
    

    PriorityQueue(): Creates a PriorityQueue with the default initial capacity (11) that orders its elements according to their natural ordering.

    This is a link to doc: https://docs.oracle.com/javase/8/docs/api/java/util/PriorityQueue.html

提交回复
热议问题