Here you can find the source of toList(final T[] array)
Parameter | Description |
---|---|
T | The type of item contained in the provided array. |
array | The array of items to include in the list. |
public static <T> List<T> toList(final T[] array)
//package com.java2s; /*/* w w w .j a v a 2 s . co m*/ * Copyright (C) 2008-2018 Ping Identity Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License (GPLv2 only) * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see <http://www.gnu.org/licenses>. */ import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { /** * Creates a modifiable list with all of the items of the provided array in * the same order. This method behaves much like {@code Arrays.asList}, * except that if the provided array is {@code null}, then it will return a * {@code null} list rather than throwing an exception. * * @param <T> The type of item contained in the provided array. * * @param array The array of items to include in the list. * * @return The list that was created, or {@code null} if the provided array * was {@code null}. */ public static <T> List<T> toList(final T[] array) { if (array == null) { return null; } final ArrayList<T> l = new ArrayList<>(array.length); l.addAll(Arrays.asList(array)); return l; } }