![]() |
VOOZH | about |
In Java, the equals() method of the Set class is used to compare two sets for equality. It checks if two sets contain the same elements regardless of their order.
Example 1: This example demonstrates how to compare two HashSet collections for equality of type string using the equals() method.
First Set: [A, B, C, D, E] Second Set: [A, B, C, D, E] Are both set equal? true
boolean equals(Object o)
Example 2: This example demonstrates how to compare two HashSet collections for equality of type integer using the equals() method.
First Set: [50, 20, 40, 10, 30] Second Set: [20, 10, 30] Are both set equal? false