List of usage examples for java.util Set remove
boolean remove(Object o);
From source file:MainClass.java
public static void main(String[] a) { String elements[] = { "A", "B", "C", "D", "E" }; Set set = new HashSet(Arrays.asList(elements)); set.remove("A"); System.out.println(set);// ww w. ja va 2s. c o m }
From source file:Main.java
public static void main(String[] a) { String elements[] = { "A", "B", "C", "D", "E" }; Set<String> set = new HashSet<String>(Arrays.asList(elements)); set.remove("A"); System.out.println(set);//from www. j a va 2 s.co m }
From source file:Main.java
public static void main(String[] args) { TreeMap<String, String> treeMap = new TreeMap<String, String>(); treeMap.put("1", "One"); treeMap.put("3", "Three"); treeMap.put("2", "Two"); Set st = treeMap.keySet(); Iterator itr = st.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); }/*from w w w .j a v a2s . c o m*/ st.remove("1"); System.out.println(treeMap.containsKey("1")); }
From source file:Main.java
public static void main(String[] args) { Hashtable<String, String> ht = new Hashtable<String, String>(); ht.put("1", "One"); ht.put("2", "Two"); ht.put("3", "Three"); Set st = ht.keySet(); Iterator itr = st.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); }/*w ww . j a v a2 s . co m*/ st.remove("2"); Enumeration e = ht.keys(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }
From source file:Main.java
public static void main(String[] args) { LinkedHashMap<String, String> lHashMap = new LinkedHashMap<String, String>(); lHashMap.put("1", "One"); lHashMap.put("2", "Two"); lHashMap.put("3", "Three"); Set st = lHashMap.keySet(); Iterator itr = st.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); }//from ww w. java2 s. c o m st.remove("2"); boolean blnExists = lHashMap.containsKey("2"); System.out.println(blnExists); }
From source file:Main.java
public static void main(String[] args) { HashMap<String, String> hMap = new HashMap<String, String>(); hMap.put("1", "One"); hMap.put("2", "Two"); hMap.put("3", "Three"); Set st = hMap.keySet(); Iterator itr = st.iterator(); while (itr.hasNext()) System.out.println(itr.next()); // remove 2 from Set st.remove("2"); System.out.println(hMap.containsKey("2")); }
From source file:edu.asu.ca.kaushik.algorithms.derandomized.pe.structures.ExtInteractionGraph.java
public static void main(String[] args) { ExtInteractionGraph is = new ExtInteractionGraph(3, 4, 2); System.out.println(is);/*from www.ja v a 2 s . com*/ int[] cols = { 0, 1, 2 }; int[] syms = { 1, 0, 0 }; Interaction in = new Interaction(new ColGroup(cols), new SymTuple(syms)); System.out.println(is.contains(in)); ColGroup colGr = new ColGroup(cols); Set<IFitness> iFitnessSet = is.iSet.get(colGr); iFitnessSet.remove(new SymTuple(syms)); System.out.println(is); }
From source file:MyObject.java
public static void main(String[] args) { Set<MyObject> set = new TreeSet<>(new Comparator<MyObject>() { @Override/* w w w.j a va 2s. c o m*/ public int compare(MyObject left, MyObject right) { return left.value - right.value; } }); set.add(new MyObject(1)); set.add(new MyObject(2)); set.add(new MyObject(3)); set.add(new MyObject(1)); // '1' is already in set System.out.println("size:" + set.size());// print 3 System.out.println(set.remove(new MyObject(3))); System.out.println("size:" + set.size()); }
From source file:ZipCompare.java
public static void main(String[] args) { if (args.length != 2) { System.out.println("Usage: zipcompare [file1] [file2]"); System.exit(1);/*from w w w.j a va 2 s . c om*/ } ZipFile file1; try { file1 = new ZipFile(args[0]); } catch (IOException e) { System.out.println("Could not open zip file " + args[0] + ": " + e); System.exit(1); return; } ZipFile file2; try { file2 = new ZipFile(args[1]); } catch (IOException e) { System.out.println("Could not open zip file " + args[0] + ": " + e); System.exit(1); return; } System.out.println("Comparing " + args[0] + " with " + args[1] + ":"); Set set1 = new LinkedHashSet(); for (Enumeration e = file1.entries(); e.hasMoreElements();) set1.add(((ZipEntry) e.nextElement()).getName()); Set set2 = new LinkedHashSet(); for (Enumeration e = file2.entries(); e.hasMoreElements();) set2.add(((ZipEntry) e.nextElement()).getName()); int errcount = 0; int filecount = 0; for (Iterator i = set1.iterator(); i.hasNext();) { String name = (String) i.next(); if (!set2.contains(name)) { System.out.println(name + " not found in " + args[1]); errcount += 1; continue; } try { set2.remove(name); if (!streamsEqual(file1.getInputStream(file1.getEntry(name)), file2.getInputStream(file2.getEntry(name)))) { System.out.println(name + " does not match"); errcount += 1; continue; } } catch (Exception e) { System.out.println(name + ": IO Error " + e); e.printStackTrace(); errcount += 1; continue; } filecount += 1; } for (Iterator i = set2.iterator(); i.hasNext();) { String name = (String) i.next(); System.out.println(name + " not found in " + args[0]); errcount += 1; } System.out.println(filecount + " entries matched"); if (errcount > 0) { System.out.println(errcount + " entries did not match"); System.exit(1); } System.exit(0); }
From source file:HashSetExample.java
public static void main(String[] args) { Set<Integer> set = new HashSet<Integer>(); set.add(new Integer(1)); set.add(new Integer(2)); set.add(new Integer(3)); set.add(new Integer(4)); set.add(new Integer(5)); set.add(new Integer(6)); set.add(new Integer(7)); set.add(new Integer(8)); set.add(new Integer(9)); set.add(new Integer(10)); // Use iterator to display the vsetes System.out.println("HashSet Before: "); for (Iterator i = set.iterator(); i.hasNext();) { Integer integer = (Integer) i.next(); System.out.println(integer); }//from w w w.jav a 2 s. com // Remove the integer 6 System.out.println("\nRemove integer 6"); set.remove(new Integer(6)); // Use iterator to display the vsetes System.out.println("\nHashSet After: "); for (Iterator i = set.iterator(); i.hasNext();) { Integer integer = (Integer) i.next(); System.out.println(integer); } }