VOOZH about

URL: https://www.geeksforgeeks.org/java/abstractset-equals-method-in-java-with-examples/

⇱ Java AbstractSet equals() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java AbstractSet equals() Method

Last Updated : 11 Jul, 2025

The AbstractSetequals() Method in Java is used to check for equality between two sets. This method verifies whether the elements of one set are equal to the elements of another set.

Syntax of AbstractSet equals() Method

public boolean equals(Object o)

  • Parameter: The object "o" is to be compared for equality with this set.
  • Return Type: This method returns "true" if both sets contain the same elements, otherwise returns "false".

Example: This example checks if two sets are equal by verifying that they contain the same elements, regardless of their order.


Output
Set1: [1, 2, 3]
Set2: [1, 2, 3]
set1 equals set2?: true
Set1: [1, 2, 3]
Set3: [1, 2, 4]
set1 equals set3?: false
Comment