equals(Object): This method is available in java.util.LinkedHashSet clas 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. 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.Collection;import java.util.LinkedHashSet;public class LinkedHashSetequals {public static void main(String[] args) {LinkedHashSet<String> linkedHashSet =new LinkedHashSet<>();Collection<String> collection =new LinkedHashSet<String>();collection.add("Java");collection.add("C++");linkedHashSet.add("Hello");System.out.println(linkedHashSet.equals(collection));}}
Output:
false
No comments:
Post a Comment