The equals() method of java.util.concurrent.ConcurrentSkipListSet is an inbuilt function in Java which compares the specified object with this set for equality. It returns True if the specified object is also a set. The two sets will said to be equal if they satisfies all of the conditions stated below:
- The two sets have the same size.
- Every member of the specified set is contained in this set.
This definition ensures that the equals method works properly across different implementations of the set interface.
Parameters: The function returns a single parameter o i.e. the object to be compared for equality with this set
Return Value: The function returns boolean value. It returns true if the specified object is equal to this set, otherwise returns false.
Below programs illustrate the ConcurrentSkipListSet.equals() method:
Program 1: In this example both the set are equal.
Both the sets are equal Contents of the set: [10, 20, 25, 35] Contents of the descending set: [35, 25, 20, 10]
Program 2: In this example both the set are not equal
Both the sets are not equal Contents of the first set: [10, 20, 25, 35] Contents of the second set: [20, 25, 35]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.