Example usage for java.util Collections addAll

List of usage examples for java.util Collections addAll

Introduction

In this page you can find the example usage for java.util Collections addAll.

Prototype

@SafeVarargs
public static <T> boolean addAll(Collection<? super T> c, T... elements) 

Source Link

Document

Adds all of the specified elements to the specified collection.

Usage

From source file:Main.java

/** @return a new {@link ArrayList} from given array (a null array is considered like it's an empty one). */
@SafeVarargs/*from   ww w  .j a va 2s  .  c om*/
public static <E> ArrayList<E> createArrayList(E... array) {
    ArrayList<E> newCollection = new ArrayList<E>();
    if (array != null) {
        Collections.addAll(newCollection, array);
    }
    return newCollection;
}

From source file:Main.java

public static <E> Set<E> asSet(E... elements) {
    if (elements == null || elements.length == 0) {
        return Collections.emptySet();
    }//  ww  w  . java2 s .  c  o m

    if (elements.length == 1) {
        return Collections.singleton(elements[0]);
    }

    LinkedHashSet<E> set = new LinkedHashSet<E>(elements.length * 4 / 3 + 1);
    Collections.addAll(set, elements);
    return set;
}

From source file:Main.java

public static <T> Set<T> asSet(final T t, final T... ts) {
    final Set<T> set = new HashSet<T>(ts.length + 1);
    set.add(t);/* w w w . j  a  va2 s  .  c o  m*/
    Collections.addAll(set, ts);
    return set;
}

From source file:Main.java

public static Intent share(String text, String mimeType, Uri... attachments) {
    final Intent intent = new Intent();
    intent.setType(mimeType);/*from   w  w  w  .ja v a2  s  . c o  m*/
    if (attachments.length > 1) {
        intent.setAction(Intent.ACTION_SEND_MULTIPLE);
        final ArrayList<CharSequence> textExtra = new ArrayList<>();
        textExtra.add(text);
        intent.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, textExtra);
        final ArrayList<Parcelable> uris = new ArrayList<>();
        Collections.addAll(uris, attachments);
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    } else {
        intent.setAction(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, text);
        if (attachments.length > 0) {
            intent.putExtra(Intent.EXTRA_STREAM, attachments[0]);
        }
    }
    return intent;
}

From source file:Main.java

@SafeVarargs
public static <T> List<T> asList(T... values) {
    List<T> listWithValues = new ArrayList<>();
    Collections.addAll(listWithValues, values);
    return listWithValues;
}

From source file:Main.java

public static Intent share(String text, String mimeType, Uri... attachments) {
    final Intent intent = new Intent();
    intent.setType(mimeType);/*from   w ww  . java  2 s  .com*/
    if (attachments.length > 1) {
        intent.setAction(Intent.ACTION_SEND_MULTIPLE);
        final ArrayList<CharSequence> textExtra = new ArrayList<>();
        textExtra.add(text);
        intent.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, textExtra);
        final ArrayList<Parcelable> uris = new ArrayList<>();
        Collections.addAll(uris, attachments);
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    } else {
        intent.setAction(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, text);
        intent.putExtra(Intent.EXTRA_STREAM, attachments[0]);
    }
    return intent;
}

From source file:Main.java

/**
 * Returns the specified array as a Set of elements.
 * <p/>//from   www  . j a v a2 s . co  m
 * @param <T> the class type of the elements in the array.
 * @param array the object array of elements to convert to a Set.
 * @return a Set of elements contained in the specified array.
 * @see java.util.Arrays#asList(Object[])
 */
@SafeVarargs
public static <T> Set<T> asSet(final T... array) {
    Set<T> arraySet = new HashSet<T>(array.length);
    Collections.addAll(arraySet, array);
    return arraySet;
}

From source file:Main.java

public static <T> List<T> toList(T[] things) {
    if (things == null || things.length == 0) {
        return new ArrayList<T>(0);
    }//w ww .  j  ava2s .  c  om

    List<T> list = new ArrayList<T>(things.length);
    Collections.addAll(list, things);
    return list;
}

From source file:Main.java

/**
 * Returns the specified array as a List of elements.
 * <p/>/*from   w w w .ja va 2 s  .co m*/
 * @param <T> the class type of the elements in the array.
 * @param array the object array of elements to convert to a List.
 * @return a List of elements contained in the specified array.
 * @see java.util.Arrays#asList(Object[])
 */
@SafeVarargs
public static <T> List<T> asList(final T... array) {
    List<T> arrayList = new ArrayList<T>(array.length);
    Collections.addAll(arrayList, array);
    return arrayList;
}

From source file:Sets.java

/**
 * Construct a new {@link HashSet} with the provided elements, taking advantage of type inference to
 * avoid specifying the type on the rhs.
 *///from ww w.  j a v  a 2  s.  c om
public static <E> HashSet<E> newHashSet(E... elements) {
    HashSet<E> set = newHashSet();
    Collections.addAll(set, elements);
    return set;
}