List of usage examples for java.util Collections addAll
@SafeVarargs public static <T> boolean addAll(Collection<? super T> c, T... elements)
From source file:Main.java
@SafeVarargs public static <T> Set<T> set(T... items) { HashSet<T> result = new HashSet<>(items.length); Collections.addAll(result, items); return result; }
From source file:Main.java
/** * This method works like {@link Arrays#asList(Object[])}, but returns an instance of * {@link Set} instead of a list/*from w w w .j a va 2 s. co m*/ * @param array the input array * @param <T> the type of input items * @return the resulting set */ public static <T> Set<T> asSet(T... array) { final HashSet<T> set = new HashSet<T>(); Collections.addAll(set, array); return set; }
From source file:Main.java
/** * Returns data converted into list.//from w w w. j ava 2 s. c o m * * @param data data * @param <T> data type * @return data list */ public static <T> ArrayList<T> asList(final T... data) { final ArrayList<T> list = new ArrayList<T>(data.length); Collections.addAll(list, data); return list; }
From source file:Main.java
@SuppressWarnings({ "unchecked" }) public static <E> Set<E> asSet(E... elements) { if (elements == null || elements.length == 0) { return Collections.EMPTY_SET; }//from w ww . j a v a2s . com LinkedHashSet<E> set = new LinkedHashSet<E>(elements.length * 4 / 3 + 1); Collections.addAll(set, elements); return set; }
From source file:cloudify.widget.common.CollectionUtils.java
public static <T extends Collection> T addTo(Collection l, Object... os) { Collections.addAll(l, os); return (T) l; }
From source file:Main.java
/** * Merge arrays//w w w .j ava2 s . c o m * * @param array The source arrays * @return A collection that contains the contents of all the arrays passed to <code>array</code> */ public static <T> ArrayList<T> mergeLists(final T... array) { final ArrayList<T> retValue = new ArrayList<T>(); Collections.addAll(retValue, array); return retValue; }
From source file:Main.java
/** * @deprecated Replace with Collections.addAll * Populates collection with items// www . j av a 2s .c om * @param <T> * @param collection * @param items * @see java.util.Collections#addAll(java.util.Collection, java.lang.Object...) */ public static final <T> void populate(Collection<T> collection, T... items) { Collections.addAll(collection, items); }
From source file:ClassUtil.java
/** * Retrieving fields list of specified class * If recursively is true, retrieving fields from all class hierarchy * * @param clazz where fields are searching * @param recursively param/*from w w w . j a v a2 s .c om*/ * @return list of fields */ public static Field[] getDeclaredFields(Class clazz, boolean recursively) { List<Field> fields = new LinkedList<Field>(); Field[] declaredFields = clazz.getDeclaredFields(); Collections.addAll(fields, declaredFields); Class superClass = clazz.getSuperclass(); if (superClass != null && recursively) { Field[] declaredFieldsOfSuper = getDeclaredFields(superClass, recursively); if (declaredFieldsOfSuper.length > 0) Collections.addAll(fields, declaredFieldsOfSuper); } return fields.toArray(new Field[fields.size()]); }
From source file:Main.java
/** * Returns a list of objects converted from array. * * @param array//from ww w. ja v a 2 s . co m * data array * @param <T> * data type * @return data list */ public static <T> ArrayList<T> toList(final T[] array) { final ArrayList<T> list = new ArrayList<T>(array.length); Collections.addAll(list, array); return list; }
From source file:Main.java
@SuppressWarnings({ "unchecked" }) public static <E> List<E> asList(E... elements) { if (elements == null || elements.length == 0) { return Collections.EMPTY_LIST; }//from w w w. j a va2 s . c om // Avoid integer overflow when a large array is passed in int capacity = computeListCapacity(elements.length); ArrayList<E> list = new ArrayList<E>(capacity); Collections.addAll(list, elements); return list; }