javajava-collections-api

A set that contains value pairs that performs checks without accounting for the key/value order


I need a data set that contains pairs of values. And you can check whether a pair exists in such set regardless of the pair's key/value order, that is:

If the set contains

<1,5>
<8,3>

And you ask if it contains <5,1>, it will return true because the order does not matter.

I could write my own Pair class and design the hashCode() and equals() methods to account for my requirements, but I was wondering if Java has a library that serves this purpose already.


Solution

  • I guess you already know the answer, on how to implement it, I don't think there is any library in java which can help you out for this requirement. So yes please implement your Pair class with similar implementation example given by patryk, in the previous answer.