For Hashset in java, there is a .equals method comparing the elements in each set. Will this return true regardless of order?
An example, say, we have one set with elements {a, b, c} and another with elements {b, c, a}
if you use .equals on these two sets, will it return true or should it be sorted?
This should return true. The documentation states:
. true , , . , equals Set.
HashSet Set ( ), , . equals Set .
HashSet
Set
equals
Java HashSet - . . {a,b,c} {b,c,a}. , HashSet AbstractSet#equals(Object), :
{a,b,c}
{b,c,a}
AbstractSet#equals(Object)
. true, , , . , equals Set.
true
, , Set .
Set, TreeSet.
, - . , , "", -.
This means that the collection only needs to return to more time-consuming methods in the unlikely event of hash code colonization.
A hash is essentially an unordered list, so yes,
if hash A contains {1,2,3,4,5}, and hash B contains {3,1,5,4,2}, then they will be equal.