How would I see if two Java queues are equal based on the value of each of them?

I want to implement a peer override that compares two Java queue objects based on each of them having the same (by value) content.

I can probably crack some kind of code, but of course, someone has decided it is elegant already. Google search did not bring any results, so I came here further.

I appreciate any suggestions. I will also need to do the same with the ArrayList and HashMap collections.

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

This gives some clues, but apparently I need more help when it comes to collections. The types contained in the collections override equals () based on the recommendations from this link.

+3
source share
1 answer

JavaDoc java.util.Queue already points to the problem:

Queue implementations usually don’t determine the versions of equals and hashCode methods based on elements, but instead inherit versions based on identity from the Object class, because element-based equalities are not always well defined for queues with the same elements, but with different ordering properties.

, ( ) , .

. ArrayList ArrayList.equals().

, , , java.util.concurrent.LinkedBlockingQueue.toArray(), Arrays.equals(queue1AsArray,queue2AsArray);

+7

Source: https://habr.com/ru/post/1775309/


All Articles