本文主要是介绍java.util.arraylist类 toArray()方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
以前一直迷惑为什么会有这样的用法 String[] s = (String [])arrayList.toArray(new String[0]),看完API之后才明白,API 片段 如下:
public <T> T[] toArray(T[] a)
If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)
这篇关于java.util.arraylist类 toArray()方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!