Java List from Array asListFromObjectArray(Object[] at)

Here you can find the source of asListFromObjectArray(Object[] at)

Description

as List From Object Array

License

Open Source License

Parameter

Parameter Description
at a parameter

Return

a List containing the elements of the given array.

Declaration

public static <T> List<T> asListFromObjectArray(Object[] at) 

Method Source Code

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import java.util.ArrayList;

import java.util.Collection;

import java.util.List;

public class Main {
    /**/* w  ww .  jav  a  2s  .  c om*/
     * @param at
     * @return a List containing the elements of the given array.
     * @precondition at != null
     * @postcondition result != null
     * @postcondition result.size() == at.length
     */
    public static <T> List<T> asListFromObjectArray(Object[] at) {
        final List<T> result = new ArrayList<T>(at.length);
        for (Object t : at) {
            result.add((T) t);
        }
        assert result.size() == at.length;
        return result;
    }

    /**
     * @param coll
     * @postcondition (coll == null) --> (result == 0)
     * @postcondition (coll != null) --> (result == coll.size())
     */
    public static int size(Collection<?> coll) {
        return (coll == null) ? 0 : coll.size();
    }
}

Related

  1. asList(T[] array)
  2. asList(T[] array)
  3. asList(T[] array)
  4. asList(T[] array)
  5. asList(T[] array)
  6. convertArrayToList(int[] ids)
  7. convertArrayToList(List list, String[] strs)
  8. convertArrayToList(Object value)
  9. convertArrayToList(Object[] objects)