av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Java 數(shù)組內(nèi)置函數(shù)toArray詳解

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

java.util.List中的toArray函數(shù)

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)

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

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

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

假設(shè)x是一個(gè)只包含字符串的列表。下面的代碼可以用來將列表轉(zhuǎn)儲(chǔ)到一個(gè)新分配的String數(shù)組中:

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

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

覆蓋:

toArray在接口集合

參數(shù):

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

類型參數(shù):

-包含集合的數(shù)組的運(yùn)行時(shí)類型

返回:

一個(gè)包含此列表元素的數(shù)組

拋出:

如果指定數(shù)組的運(yùn)行時(shí)類型不是這個(gè)列表中每個(gè)元素的運(yùn)行時(shí)類型的超類型,則會(huì)產(chǎn)生ArrayStoreException異常

NullPointerException -如果指定的數(shù)組為空

外部注釋:

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

參數(shù):@org.jetbrains.annotations.NotNull

public static void main(String[] args) { List<Double> asList = new ArrayList<Double>() {//使用匿名內(nèi)部類來初始化。{ 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));}

運(yùn)行結(jié)果:

Java 數(shù)組內(nèi)置函數(shù)toArray詳解

到此這篇關(guān)于Java 數(shù)組內(nèi)置函數(shù)toArray詳解的文章就介紹到這了,更多相關(guān)Java toArray解析內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 欧美一级免费 | 国产成人小视频 | 九九超碰 | 成人在线一区二区 | 狠狠的日 | 成人免费精品 | 91在线亚洲 | 亚洲一二区 | 黄色一级片免费看 | 日韩av在线免费播放 | av香蕉| 无遮挡在线观看 | 亚洲永久免费视频 | 国产免费高清视频 | 精品久久久久久久久久久 | 韩国免费理论片 | 毛片av在线 | 污视频网站在线观看 | 少妇一级淫片免费看 | 伊人9999| 人人插人人爱 | 欧美日韩高清在线 | 久久精品综合 | 国产尤物视频 | a毛片视频 | 国产伦精品一区二区免费 | a级片在线 | 欧美精品在线观看视频 | 日韩城人免费 | 91免费版看片 | 91黄色免费视频 | 好了av在线| 国产精品一区二区三区免费 | 成人毛片一区二区三区 | 蜜臀久久99精品久久久久久宅男 | 久久久久女教师免费一区 | 九九热在线观看 | 午夜欧美 | 久久精品国产免费 | 欧美精品一二区 | 亚洲精品成a人在线观看 |