How to see whether two Java queues are equal according to the content value of each queue?

I want to implement an equals override, which compares two Java queue objects based on them, and the contents of each object are equal (by value)

I might crack some code, but someone must have solved the problem gracefully Google search didn't produce any results, so I came here next

I appreciate any suggestions I also need to do the same for the ArrayList and HashMap collections

By the way, for equals (), I use it as my guide: http://www.javapractices.com/topic/TopicAction.do?Id=17

It provides some tips, but obviously I need more help to collect The types contained in the collection override equals () according to the recommendations of the link

Solution

java. util. The Javadoc of queue has explained the problem:

Therefore, if you want to operate according to the contained objects, you need to implement logic for your own use cases (or reuse some libraries)

For example For ArrayList, you simply call ArrayList equals().

For queues, I will use a practical method to convert them to arrays using, for example, arrays java. util. concurrent. LinkedBlockingQueue. Toarray() and then use arrays equals(queue1AsArray,queue2AsArray);

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
分享
二维码
< <上一篇
下一篇>>