List of usage examples for java.util Collection remove
boolean remove(Object o);
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"); Collection c = ht.values(); Iterator itr = c.iterator();// ww w .j a va 2 s . c o m while (itr.hasNext()) { System.out.println(itr.next()); } c.remove("One"); Enumeration e = ht.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }
From source file:Main.java
public static void main(String[] args) { Collection<String> names = new ArrayList<>(); System.out.printf("Size = %d, Elements = %s%n", names.size(), names); names.add("XML"); names.add("HTML"); names.add("CSS"); System.out.printf("Size = %d, Elements = %s%n", names.size(), names);//from ww w.j a v a2 s.c o m names.remove("CSS"); System.out.printf("Size = %d, Elements = %s%n", names.size(), names); names.clear(); System.out.printf("Size = %d, Elements = %s%n", names.size(), names); }
From source file:PlanetSet.java
public static void main(String args[]) { String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; Collection planets = new ArrayList(); for (int i = 0, n = names.length; i < n; i++) { planets.add(names[i]);/*from w w w . j a v a 2 s . c o m*/ } String s[] = (String[]) planets.toArray(new String[0]); for (int i = 0, n = s.length; i < n; i++) { System.out.println(s[i]); } planets.remove(names[3]); System.out.println(names[1] + " " + planets.contains(names[1])); System.out.println(names[3] + " " + planets.contains(names[3])); }
From source file:org.apache.batchee.cli.BatchEECLI.java
public static void main(final String[] args) { final Iterator<CliConfiguration> configuration = ServiceLoader.load(CliConfiguration.class).iterator(); final CliConfiguration cliConfiguration = configuration.hasNext() ? configuration.next() : new DefaultCliConfiguration(); final Map<String, Class<? extends Runnable>> commands = new TreeMap<String, Class<? extends Runnable>>(); if (cliConfiguration.addDefaultCommands()) { for (final Class<? extends Runnable> type : Arrays.asList(Names.class, Start.class, Restart.class, Status.class, Running.class, Stop.class, Abandon.class, Instances.class, Executions.class, StepExecutions.class, Eviction.class)) { addCommand(commands, type);/* ww w .j a va2 s.co m*/ } } final Iterator<Class<? extends UserCommand>> userCommands = cliConfiguration.userCommands(); if (userCommands != null) { while (userCommands.hasNext()) { addCommand(commands, userCommands.next()); } } if (args == null || args.length == 0) { System.err.print(help(commands)); return; } final Class<? extends Runnable> cmd = commands.get(args[0]); if (cmd == null) { if (args[0].equals("help")) { if (args.length > 1) { final Class<? extends Runnable> helpCmd = commands.get(args[1]); if (helpCmd != null) { printHelp(helpCmd.getAnnotation(Command.class), buildOptions(helpCmd, new HashMap<String, Field>())); return; } } // else let use the default help } System.err.print(help(commands)); return; } // build the command now final Command command = cmd.getAnnotation(Command.class); if (command == null) { System.err.print(help(commands)); return; } final Map<String, Field> fields = new HashMap<String, Field>(); final Options options = buildOptions(cmd, fields); final Collection<String> newArgs = new ArrayList<String>(asList(args)); newArgs.remove(newArgs.iterator().next()); final CommandLineParser parser = new DefaultParser(); try { final CommandLine line = parser.parse(options, newArgs.toArray(new String[newArgs.size()])); cliConfiguration.decorate(instantiate(cmd, cliConfiguration, fields, !newArgs.isEmpty(), line)).run(); } catch (final ParseException e) { printHelp(command, options); } catch (final RuntimeException e) { Class<?> current = e.getClass(); while (current != null) { final Exit annotation = current.getAnnotation(Exit.class); if (annotation != null) { System.exit(annotation.value()); } current = current.getSuperclass(); } throw e; } catch (final InstantiationException e) { throw new IllegalStateException(e); } catch (final IllegalAccessException e) { throw new IllegalStateException(e); } }
From source file:Main.java
public static void remove(Collection c, Object o) { c.remove(o); }
From source file:Main.java
public static <E> Collection<E> excluding(Collection<E> collection, E object) throws Exception { collection.remove(object); return collection; }
From source file:Main.java
/** * Removes objects in array to the given collection * //from w ww .j av a 2 s .com * @param c * collection from which remove each element of array. * @param array * ~ items * @return the same collection which is passed as argument(but without * element from array) */ public static <E, T extends E> Collection<E> removeAll(Collection<E> c, T... array) { for (T obj : array) { c.remove(obj); } return c; }
From source file:Main.java
/** * Removes objects in array to the given collection * * @return the same collection which is passed as argument *///from www. ja v a 2 s .c o m @SuppressWarnings("unchecked") public static <E, T extends E> Collection<E> removeAll(Collection<E> c, T... array) { for (T obj : array) c.remove(obj); return c; }
From source file:Main.java
public static <K, V> void removeFromMultiMap(Map<K, Collection<V>> map, K key, V val) { Collection<V> col = map.get(key); if (col == null) return;//from w ww.j av a2 s .c om col.remove(val); }
From source file:Main.java
/** * @return all the elements of first without any of those in second *///from w w w. j av a2 s.c o m public static <E> Collection<E> less(Collection<E> first, Collection<E> second) { Collection<E> accum = new ArrayList<E>(first); for (E e : second) { accum.remove(e); } return accum; }