List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:MainClass.java
public static void main(String args[]) { HashSet<String> hs = new HashSet<String>(); hs.add("B"); hs.add("A");/*from w w w.j ava 2s . co m*/ hs.add("D"); hs.add("E"); hs.add("C"); hs.add("F"); System.out.println(hs); }
From source file:Main.java
public static void main(String[] args) { HashSet<Integer> hSet = new HashSet<Integer>(); hSet.add(new Integer("1")); hSet.add(new Integer("2")); hSet.add(new Integer("3")); Iterator itr = hSet.iterator(); while (itr.hasNext()) System.out.println(itr.next()); }
From source file:Main.java
public static void main(String[] args) { HashSet<String> hashSet = new HashSet<String>(); hashSet.add("A"); hashSet.add("B"); hashSet.add("D"); hashSet.add("E"); hashSet.add("F"); Enumeration e = Collections.enumeration(hashSet); while (e.hasMoreElements()) System.out.println(e.nextElement()); }
From source file:Main.java
public static void main(String[] args) { HashSet<String> hashSet = new HashSet<String>(); hashSet.add("A"); hashSet.add("B"); hashSet.add("D"); hashSet.add("E"); hashSet.add("F"); Enumeration e = Collections.enumeration(hashSet); while (e.hasMoreElements()) { System.out.println(e.nextElement()); }//from w w w .ja va2 s.c om }
From source file:Main.java
public static void main(String args[]) { HashSet<String> newset = new HashSet<String>(); newset.add("Learning"); newset.add("from"); newset.add("java2s.com"); System.out.println("Values before remove: " + newset); // remove "Easy" from set boolean isremoved = newset.remove("from"); System.out.println("Return value after remove: " + isremoved); System.out.println("Values after remove: " + newset); }
From source file:Main.java
public static void main(String[] args) { HashSet<Integer> hSet = new HashSet<Integer>(); hSet.add(new Integer("1")); hSet.add(new Integer("2")); hSet.add(new Integer("3")); System.out.println(hSet);//from ww w . jav a 2s. c o m hSet.clear(); System.out.println(hSet); System.out.println(hSet.isEmpty()); }
From source file:Main.java
public static void main(String[] args) { HashSet<Integer> hSet = new HashSet<Integer>(); hSet.add(new Integer("1")); hSet.add(new Integer("2")); hSet.add(new Integer("3")); System.out.println(hSet);//from w ww .ja v a 2 s . co m boolean blnRemoved = hSet.remove(new Integer("2")); System.out.println(blnRemoved); System.out.println(hSet); }
From source file:Main.java
public static void main(String args[]) { HashSet<String> newset = new HashSet<String>(); // populate hash set newset.add("Learning"); newset.add("from"); newset.add("java2s.com"); System.out.println("Size of the set: " + newset.size()); }
From source file:Main.java
public static void main(String args[]) { HashSet<String> newset = new HashSet<String>(); // populate hash set newset.add("Learning"); newset.add("from"); newset.add("java2s.com"); // checking elements in hash set System.out.println("Hash set values: " + newset); }
From source file:Main.java
public static void main(String args[]) { HashSet<String> newset = new HashSet<String>(); // populate hash set newset.add("Learning"); newset.add("from"); newset.add("java2s.com"); // check the existence of element boolean exist = newset.contains("Simply"); System.out.println("Is the element 'Simply' exists: " + exist); }