How to find does HashSet contains elements or not

Returns true if this set contains the specified element.we can say returns true if and only if this set contains an element e such that (o==null ? e==null :
o.equals(e)).

import java.util.HashSet;
import java.util.Set;

public class ContailsElement {

public static void main(String[] args) {

Set<String> hs = new HashSet<String>();
hs.add(“java”);
hs.add(“php”);
hs.add(“html”);
hs.add(“javascript”);
hs.add(“mysql”);

//print hashset
System.out.println(“hashset = “+hs);

System.out.println(hs.contains(“java”));
System.out.println(hs.contains(“HTml”));
System.out.println(hs.contains(“delhi”));

}

}

hashset = [javascript, php, html, java, mysql]

true

false

false

Leave a Reply

Your email address will not be published. Required fields are marked *

32 − = 31