提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将列表转换为数组
//package com.nowjava; import java.util.List;/** 来自 时 代 Java - nowjava.com**/ public class Main { public static void main(String[] argv) { List oList = java.util.Arrays.asList("asdf", "nowjava.com"); System.out.println(java.util.Arrays.toString(list2Array(oList))); } public static <T> T[] list2Array(List<T> oList) { Object[] oArray = oList.toArray(new Object[] {}); T[] ts = (T[]) oArray; return ts; /* from N o w J a v a . c o m */ } }