Java examples for Collection Framework:HashSet
Check if a particular element exists in HashSet
import java.util.HashSet; public class Main { public static void main(String[] args) { HashSet hSet = new HashSet(); /*from www . j ava 2s.c om*/ hSet.add(new Integer("1")); hSet.add(new Integer("2")); hSet.add(new Integer("3")); boolean blnExists = hSet.contains(new Integer("3")); System.out.println("3 exists in HashSet ? : " + blnExists); } }