简体   繁体   中英

Java PriorityQueue(PriorityQueue) constructor

Is the java API PriorityQueue constructor that takes another priority queue destructive to the argument? If so, is its clone() method adequate for creating a shallow copy?

No, it is not destructive. Pretty much all the collection classes have copy constructors, and are non-destructive by convention.

The reason there are overloaded constructors is for efficiency; when a PQ or SortedSet is supplied, one can imagine that the initial population of elements can be O(n) instead of O(n log n)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM