List of usage examples for java.util Collection clear
void clear();
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 w w w. jav a 2 s.c om*/ 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:Main.java
public static <T> void replaceValuesInCollection(Collection<T> from, Collection<T> to) { to.clear(); if (from != null) { to.addAll(from);//from www. j a va 2s . c o m } }
From source file:Main.java
public static void clear(Collection c) { if (c != null) { c.clear(); } }
From source file:Main.java
public static <T> Collection<T> defaultCollection(Collection<T> col, int size, T defaultValue) { try {/* w ww. j av a 2 s. c om*/ col.clear(); } catch (Exception e) { } for (int i = 0; i < size; i++) { col.add(defaultValue); } return col; }
From source file:Main.java
public static int clear(final Collection collection) { final int size = collection.size(); collection.clear(); return size;// w w w . j a v a 2 s .co m }
From source file:Main.java
/** * Removes all elements from the given collection. * * @param collection The collection to be cleared. * @param <E> The component type of the collection. * @return The cleared collection. *//*from w w w .j av a2 s. c o m*/ public static <E> Collection<E> clear(Collection<E> collection) { if (collection != null) { collection.clear(); } return collection; }
From source file:org.opoo.util.CollectionUtils.java
public static void fill(Collection c, Object val, int size) { c.clear(); int i = 0;//w w w .ja v a2 s .co m while (i < size) { c.add(val); i++; } }
From source file:Main.java
/** Copy elements from src to dest. * //from w ww . ja v a 2 s . c o m * @param src - Collection containing data to be copied. * @param dest - Collection to have the data copied to. * @param clearDestination - whether to clear all contents from destination prior to copying. */ public static <T> void copyElements(Collection<? extends T> src, Collection<? super T> dest, boolean clearDestination) { if (clearDestination) { dest.clear(); } for (T t : src) { dest.add(t); } }
From source file:Main.java
public static void decodeFromString(final Collection<Long> values, final String q, int maxLen) { values.clear(); if (q == null) { return;//w w w.jav a 2 s . co m } int qlen = q.length(); if (qlen <= 1) { return; } long n = 0; int shift = 0; for (int i = 0; i < qlen; i++) { char c = q.charAt(i); if (c == ';') { if (maxLen > 0 && n >= maxLen) { // bogus history data values.clear(); break; } values.add(n); n = 0; shift = 0; } else { if (c >= '0' && c <= '9') { n += ((c - '0') << shift); } else if (c >= 'a' && c <= 'f') { n += ((10 + c - 'a') << shift); } else { // bogus history data values.clear(); break; } shift += 4; } } }
From source file:Main.java
/** * Remove all object from collection to other collection * @param <T>//from www .ja v a2s .co m * @param from source collection * @param to target collection */ public static <T> void moveAllObject(Collection<T> from, Collection<T> to) { if (!from.isEmpty()) { to.addAll(from); from.clear(); } }