Java List to Array listToArray(List list)

Here you can find the source of listToArray(List list)

Description

list To Array

License

Open Source License

Declaration

public static <T> T[] listToArray(List<T> list) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. 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:/*ww w  .  ja  v a2s  .  co  m*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.util.List;

public class Main {
    public static <T> T[] listToArray(List<T> list) {

        @SuppressWarnings("unchecked")
        T[] array = (T[]) new Object[list.size()];

        for (int i = 0; i < list.size(); i++) {
            T f = list.get(i);
            array[i] = (f != null ? f : null); // Or whatever default you want.
        }
        return array;
    }
}

Related

  1. ListToArray(List list)
  2. listToArray(List list)
  3. ListToArray(List> values)
  4. listToArray(List list)
  5. listToArray(List stringList)
  6. toArray(Collection list)
  7. toArray(Collection list)
  8. toArray(final List list)
  9. toArray(final List list)