LinkedHashSet equals() method in Java with Example
The equals() method of java.util.LinkedHashSet class is used to compare the specified object with this set for equality. Returns true if and only if the specified object is also a set, both sets have the same size, and all corresponding pairs of elements in the two sets are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two sets are defined to be equal if they contain the same elements in any order.
public boolean equals(Object o)
Parameters: This method takes the object o as a parameter to be compared for equality with this set.
Returns Value: This method returns true if the specified object is equal to this set. Below are examples to illustrate the equals() method.
First LinkedHashSet: [A, B, C, D, E] Second LinkedHashSet: [A, B, C, D, E] Are both set equal: true
First LinkedHashSet: [10, 20, 30, 40, 50] Second LinkedHashSet: [10, 20, 30] Are both set equal: false
My Personal Notes arrow_drop_up
Please Login to comment...