List of usage examples for java.util HashSet HashSet
public HashSet()
From source file:FindDups.java
public static void main(String args[]) { Set s = new HashSet(); String[] values = new String[] { "java", "java2", "java2s", "javas", "java" }; for (int i = 0; i < values.length; i++) if (!s.add(values[i])) System.out.println("Duplicate detected: " + values[i]); System.out.println(s.size() + " distinct words detected: " + s); }
From source file:Main.java
public static void main(String[] args) { HashSet<Integer> hSet = new HashSet<Integer>(); System.out.println("Size of HashSet : " + hSet.size()); hSet.add(new Integer("1")); hSet.add(new Integer("2")); hSet.add(new Integer("3")); System.out.println(hSet.size()); hSet.remove(new Integer("1")); System.out.println(hSet.size()); }
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<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); // clear set values newset.clear();//from w ww . j a v a 2s .co m System.out.println("Hash set values after clear: " + newset); }
From source file:MainClass.java
public static void main(String[] a) { Set set = new HashSet(); set.add("Hello"); if (set.add("Hello")) { System.out.println("addition successful"); } else {/*from w w w . ja v a2 s . com*/ System.out.println("addition failed"); } }
From source file:Main.java
public static void main(String[] a) { Set<String> set = new HashSet<String>(); set.add("Hello"); if (set.add("Hello")) { System.out.println("addition successful"); } else {//w w w . j av a2 s.c om System.out.println("addition failed"); } }
From source file:FindDups.java
public static void main(String[] args) { Set<String> s = new HashSet<String>(); for (String a : args) if (!s.add(a)) System.out.println("Duplicate detected: " + a); System.out.println(s.size() + " distinct words: " + s); }
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);// ww w . j a v a2 s . co m hSet.clear(); System.out.println(hSet); System.out.println(hSet.isEmpty()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Set set1 = new HashSet(); set1.clear(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Set set1 = new HashSet(); Set set2 = new HashSet(); set1.removeAll(set2);//from w ww. j a v a 2 s . co m }