If a hash set contain a certain element
boolean contains(Object o)
- Returns true if this set contains the specified element.
import java.util.HashSet;
public class Main{
public static void main(String args[]) {
HashSet<String> hs = new HashSet<String>();
hs.add("java2s.com");
hs.add("A");
hs.add("D");
hs.add("E");
hs.add("C");
hs.add("j a v a2s.com");
System.out.println(hs);
System.out.println(hs.contains("java2s.com"));
}
}
The output:
[D, E, j a v a2s.com, A, java2s.com, C]
true