how to write write a set for unordered pair in Java

前端 未结 5 1784
夕颜
夕颜 2020-12-31 18:58

I need to have a Set (HashSet) such that if I insert a pair (a, b) and if (b, a) is already in the set, the insertion would just be ignored. How to

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 19:07

    Override the equals() and hashCode() methods of the Pair class to treat both (a,b) and (b,a) as equal.

提交回复
热议问题