List中的toArray()怎么使用?
List中的toArray()怎么使用?
在程序中,往往得到一个List, 程序要求对应赋值给一个array, 可以这样写程序,for example: Long[] l = new Long[list。size()]; for(int i=0;i]; list。toArray(l); 2。
Long[] l = (Long[]) list。toArray(new Long[0]); 3。 Long[] a = new Long[]; Long[] l = (Long[]) list。toArray(a); ----------------------------------------------------------------- java sdk doc 上讲: public Object[] toArray(Object[] a) a--the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose。
如果这个数组a足够大,就会把数据全放进去,返回的数组也是指向这个数组;要是不够大,就申请一个跟参数同样类型的数组,把值放进去,然后返回。
答:一. Incident import java.util.ArrayList; import java.util.List; public class Test...详情>>