亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

您的位置:首頁技術文章
文章詳情頁

Java 數組內置函數toArray詳解

瀏覽:73日期:2022-08-09 16:36:20

java.util.List中的toArray函數

java.util.List<E> @NotNull public abstract <T> T[] toArray(@NotNull T[] a)Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.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 list 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.)Like the toArray() method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.Suppose x is a list known to contain only strings. The following code can be used to dump the list into a newly allocated array of String: String[] y = x.toArray(new String[0]); Note that toArray(new Object[0]) is identical in function to toArray().Overrides:toArray in interface CollectionParams: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.Type parameters:<T> ? the runtime type of the array to contain the collectionReturns:an array containing the elements of this listThrows:ArrayStoreException ? if the runtime type of the specified array is not a supertype of the runtime type of every element in this listNullPointerException ? if the specified array is nullExternal annotations:Abstract method toArray: @org.jetbrains.annotations.NotNullParameter a: @org.jetbrains.annotations.NotNull

翻譯java.util.List @NotNull

public abstract T[] toArray(@NotNull T[] a)

返回一個包含列表中所有元素的數組(從第一個元素到最后一個元素);返回數組的運行時類型是指定數組的運行時類型。如果列表適合指定的數組,則在其中返回該列表。否則,將使用指定數組的運行時類型和該列表的大小分配一個新數組。

如果列表適合指定的有空間的數組(即,數組的元素比列表的多),則緊挨著列表末尾的數組中的元素被設為null。(只有當調用者知道列表不包含任何空元素時,這在確定列表的長度時才有用。)

與toArray()方法一樣,該方法充當基于數組和基于集合的api之間的橋梁。此外,這種方法允許精確控制輸出數組的運行時類型,在某些情況下,可以用于節省分配成本。

假設x是一個只包含字符串的列表。下面的代碼可以用來將列表轉儲到一個新分配的String數組中:

String[] y = x.toArray(new String[0]);

注意toArray(新對象[0])在函數中與toArray()相同。

覆蓋:

toArray在接口集合

參數:

A -如果列表足夠大,則存放列表中所有元素的數組;否則,將為此目的分配相同運行時類型的新數組。

類型參數:

-包含集合的數組的運行時類型

返回:

一個包含此列表元素的數組

拋出:

如果指定數組的運行時類型不是這個列表中每個元素的運行時類型的超類型,則會產生ArrayStoreException異常

NullPointerException -如果指定的數組為空

外部注釋:

抽象方法:@org.jetbrains.annotations.NotNull

參數:@org.jetbrains.annotations.NotNull

public static void main(String[] args) { List<Double> asList = new ArrayList<Double>() {//使用匿名內部類來初始化。{ add(35.6); add(3.2); add(90.);} }; Double []sumVenderNumArray = new Double[]{333333.34,999.9,93.45,23.4,33.}; Double [] sumVenderNumNum = asList.toArray(sumVenderNumArray); System.out.println(JSONObject.toJSONString(sumVenderNumNum));}

運行結果:

Java 數組內置函數toArray詳解

到此這篇關于Java 數組內置函數toArray詳解的文章就介紹到這了,更多相關Java toArray解析內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Java
相關文章:
主站蜘蛛池模板: www.精品国产| 99精品视频99 | 杨幂国产精品福利在线观看 | 免费国产精品视频 | 又www又黄又爽啪啪网站 | 97国产免费全部免费观看 | 韩国午夜三级理论 | 欧美三级真做在线观看 | 日本三级香港三级人妇 m | 精品久久网 | 美女舒服好紧太爽了视频 | aaa级大片| 欧美成人精品久久精品 | 日韩精品中文字幕一区二区三区 | 精品国产欧美另类一区 | 免费精品一区二区三区在线观看 | 在线视频一二三区2021不卡 | 成人免费观看www在线 | 在线看国产视频 | 亚洲国产精品看片在线观看 | 毛片大全在线 | 欧美特级一级毛片 | 欧美成人 一区二区三区 | 中文字幕精品一区二区三区视频 | 日韩特级黄色片 | 欧美性猛片xxxxⅹ免费 | 一级作爱视频免费观看 | 在线观看免费av网站 | 日本精品久久久久久久 | 午夜剧场福利社 | 免费韩国一级毛片 | 久久久久综合一本久道 | 久久精品国内一区二区三区 | 大臿蕉香蕉大视频成人 | 欧美成人h精品网站 | 亚洲性在线观看 | 亚洲欧美一区二区三区在饯 | 欧美日韩一区二区三区久久 | 三级免费网站 | 日韩一级影片 | 一区视频在线 |