Here you can find the source of arrayAsList(Object[] array)
Parameter | Description |
---|---|
array | the Object[] to convert (may be null) |
public static List<Object> arrayAsList(Object[] array)
//package com.java2s; /* ******************************************************************* * Copyright (c) 1999-2001 Xerox Corporation, * 2002 Palo Alto Research Center, Incorporated (PARC). * All rights reserved. /* w w w . j a va2 s .co m*/ * This program and the accompanying materials are made available * under the terms of the Eclipse Public License v1.0 * which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Xerox/PARC initial implementation * ******************************************************************/ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public class Main { /** * Replacement for Arrays.asList(..) which gacks on null and returns a List in which remove is an unsupported operation. * * @param array the Object[] to convert (may be null) * @return the List corresponding to array (never null) */ public static List<Object> arrayAsList(Object[] array) { if ((null == array) || (1 > array.length)) { return Collections.emptyList(); } ArrayList<Object> list = new ArrayList<Object>(); list.addAll(Arrays.asList(array)); return list; } }