Java ArrayList Create createArrayList(final DataType first, final DataType second)

Here you can find the source of createArrayList(final DataType first, final DataType second)

Description

Creates a new ArrayList from the given pair of values.

License

Open Source License

Parameter

Parameter Description
DataType The data type.
first The first value.
second The second value.

Return

A new array list with the two elements in it.

Declaration

public static <DataType> ArrayList<DataType> createArrayList(final DataType first, final DataType second) 

Method Source Code


//package com.java2s;
/*/*from  w w w  .  ja  va2s  .co  m*/
 * File:                CollectionUtil.java
 * Authors:             Justin Basilico
 * Company:             Sandia National Laboratories
 * Project:             Cognitive Foundry
 *
 * Copyright March 25, 2008, Sandia Corporation.
 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
 * license for use of this work by or on behalf of the U.S. Government. Export
 * of this program may require a license from the United States Government.
 * See CopyrightHistory.txt for complete details.
 *
 */

import java.util.ArrayList;

public class Main {
    /**
     * Creates a new ArrayList from the given pair of values.
     *
     * @param <DataType> The data type.
     * @param first The first value.
     * @param second The second value.
     * @return A new array list with the two elements in it.
     */
    public static <DataType> ArrayList<DataType> createArrayList(final DataType first, final DataType second) {
        final ArrayList<DataType> result = new ArrayList<DataType>(2);
        result.add(first);
        result.add(second);
        return result;
    }
}

Related

  1. asArrayList(Collection collection)
  2. createArrayList()
  3. createArrayList()
  4. createArrayList(Collection arg)
  5. createArrayList(E... array)
  6. createArrayList(Iterable items, int size)
  7. createArrayList(Object[] a)
  8. createArrayList(String[] a)
  9. createArrayList(T... objects)