Convert list to Array - Java Collection Framework

Java examples for Collection Framework:Array Convert

Description

Convert list to Array

Demo Code


//package com.java2s;

import java.util.List;

public class Main {
    public static void main(String[] argv) {
        List oList = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(java.util.Arrays.toString(list2Array(oList)));
    }// www.ja v  a2s  .  c o  m

    public static <T> T[] list2Array(List<T> oList) {
        Object[] oArray = oList.toArray(new Object[] {});
        T[] ts = (T[]) oArray;
        return ts;
    }
}

Related Tutorials