equals(Object): This method is available in java.util.HashSet class of Java.
Syntax:
boolean java.util.AbstractSet.equals(Object o)
This method takes one argument. This method compares the specified object with this set for equality.
Note: Returns true if the given object is also a set, the two sets have the same size, and every member of the given set is contained in this set.
Parameters: One parameter is required for this method.
o: object to be compared for equality with this set.
Returns: true if the specified object is equal to this set.
Exceptions: NA
Approach
Java
import java.util.HashSet;public class HashSetequals {public static void main(String[] args) {HashSet<String> hashSet = new HashSet<String>();hashSet.add("Hello");hashSet.add("Java");hashSet.add("C++");hashSet.add("Hello");HashSet<String> hashSet2 = new HashSet<String>();System.out.println(hashSet2.equals(hashSet));}}
Output:
false
No comments:
Post a Comment