Comparing “queue” objects in Java

I am currently studying the properties of the queue interface and encounter the following declaration in Java documentation:

I'm not quite sure what this paragraph means when comparing "queue" objects of the same implementation type with different implementation types Can someone explain to me how to compare "queue" objects?

Solution

I think the document description queue implementation usually does not override the default equals method in the object class, because the sorting of elements in queue may be very different for each implementation, so comparing them in a general way may produce unexpected results

If you want to compare queue objects according to your own standards, you can implement comparator < queue > class (especially the comparison method) You can then use this method to directly compare two queues, or use it to sort a collection of queues, and so on

See Javadoc for comparator

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>