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.
Syntax:
ConcurrentSkipListSet.equals(Object o)
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.
Output:
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