contains(Object): This method is available in java.util.LinkedHashSet class of Java.
Syntax:
boolean java.util.HashSet.contains(Object o)
This method takes one argument. This method returns true if this set contains the specified element.
Parameters: One parameter is required for this method.
o: element whose presence in this set is to be tested.
Returns: true if this set contains the specified element.
Exceptions: NA
Approach
Java
import java.util.LinkedHashSet;public class LinkedHashSetcontains {public static void main(String[] args) {LinkedHashSet<String> linkedHashSet =new LinkedHashSet<>();linkedHashSet.add("Hello");Object o = "Hello";System.out.println(linkedHashSet.contains(o));}}
Output:
true
No comments:
Post a Comment