Java ArrayList Create newArrayList(T... objs)

Here you can find the source of newArrayList(T... objs)

Description

Returns the value mapped by key, or if no mapping exists, puts to map and returns the value supplied by valueSupplier.

License

Apache License

Declaration
















public static <T> List<T> newArrayList(T... objs) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

import java.util.List;
import java.util.Map;

public class Main {
    /**/*w  ww. j a  v  a2s  .c  o m*/
     * Returns the value mapped by key, or if no mapping exists, puts to map and
     * returns the value supplied by valueSupplier.
     */
    //   public static <K, V> V getOrPut(Map<K, V> map, K key,
    //         Supplier<V> valueSupplier) {
    //      if (map.containsKey(key)) {
    //         return map.get(key);
    //      }
    //      V val = valueSupplier.get();
    //      map.put(key, val);
    //      return val;
    //   }
    //
    //   public static <K, V> boolean equal(Map<? extends K, ? extends V> left,
    //         Map<? extends K, ? extends V> right) {
    //      return Maps.difference(left, right).areEqual();
    //   }

    public static <T> List<T> newArrayList(T... objs) {
        List<T> results = new ArrayList<T>();
        results.addAll(Arrays.asList(objs));
        return results;
    }

    public static <E> ArrayList<E> newArrayList() {
        return new ArrayList<E>();
    }

    /**
     * Adds thingsToAdd to thingsToBeAddedTo.
     * 
     * @param thingsToBeAddedTo
     *            , which must be non-null.
     * @throws IllegalArgumentException
     *             if thingsToBeAddedTo is null.
     * 
     */
    public static <E> void addAll(final Collection<? super E> thingsToBeAddedTo,
            final Collection<? extends E> thingsToAdd) {
        if (thingsToBeAddedTo == null) {
            throw new IllegalArgumentException("There's no thingsToBeAddedTo!");
        }

        if (!isEmpty(thingsToAdd)) {
            thingsToBeAddedTo.addAll(thingsToAdd);
        }
    }

    public static boolean isEmpty(Iterable<?> i) {
        if (i instanceof Collection)
            return ((Collection<?>) i).isEmpty();
        return i == null || !i.iterator().hasNext();
    }

    public static boolean isEmpty(Map<?, ?> p_oCol) {
        return p_oCol == null || p_oCol.isEmpty();
    }
}

Related

  1. newArrayList(Iterable iterable)
  2. newArrayList(T anObj)
  3. newArrayList(T... elements)
  4. newArrayList(T... items)
  5. newArrayList(T... objectList)
  6. newArrayList(X... args)
  7. newArrayListOnNull(List list)
  8. newArrayListSized(Iterable fromSize)
  9. newArrayListWithCapacity(int initSize)