最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2021年06月28日 16:21:44   作者:九童  
這篇文章主要介紹了Java 數(shù)組內(nèi)置函數(shù)toArray詳解,文本詳細的講解了toArray底層的代碼和文檔,需要的朋友可以參考下

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 Collection
Params:
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 collection
Returns:
an array containing the elements of this list
Throws:
ArrayStoreException – if the runtime type of the specified array is not a supertype of the runtime type of every element in this list
NullPointerException – if the specified array is null
External annotations:
Abstract method toArray: @org.jetbrains.annotations.NotNull
Parameter a: @org.jetbrains.annotations.NotNull

翻譯
java.util.List @NotNull

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

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

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

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

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

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

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

覆蓋:

toArray在接口集合

參數(shù):

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

類型參數(shù):

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

返回:

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

拋出:

如果指定數(shù)組的運行時類型不是這個列表中每個元素的運行時類型的超類型,則會產(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));

}

運行結(jié)果:

在這里插入圖片描述

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

相關(guān)文章

  • 為什么說HashMap線程不安全

    為什么說HashMap線程不安全

    本文主要介紹了為什么說HashMap線程不安全,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-04-04
  • SpringBoot+Vue實現(xiàn)數(shù)據(jù)添加功能

    SpringBoot+Vue實現(xiàn)數(shù)據(jù)添加功能

    這篇文章主要介紹了SpringBoot+Vue實現(xiàn)數(shù)據(jù)添加功能,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-03-03
  • springMVC框架下JQuery傳遞并解析Json數(shù)據(jù)

    springMVC框架下JQuery傳遞并解析Json數(shù)據(jù)

    json作為一種輕量級的數(shù)據(jù)交換格式,在前后臺數(shù)據(jù)交換中占據(jù)著非常重要的地位,這篇文章主要介紹了springMVC框架下JQuery傳遞并解析Json數(shù)據(jù),有興趣的可以了解一下。
    2017-01-01
  • 關(guān)于Scanner中nextInt()、nextLine()等方法總結(jié)與問題解決

    關(guān)于Scanner中nextInt()、nextLine()等方法總結(jié)與問題解決

    這篇文章主要介紹了關(guān)于Scanner中nextInt()、nextLine()等方法總結(jié)與問題解決,具有很好的參考價值,希望對大家有所幫助。
    2022-11-11
  • springboot集成mqtt超級詳細步驟

    springboot集成mqtt超級詳細步驟

    這篇文章主要介紹了springboot集成mqtt超級詳細步驟,本文分步驟結(jié)合實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-06-06
  • 使用eclipse打包Maven項目的實現(xiàn)步驟

    使用eclipse打包Maven項目的實現(xiàn)步驟

    本文主要介紹了使用eclipse打包Maven項目的實現(xiàn)步驟,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-03-03
  • SpringBoot+SpringSecurity+jwt實現(xiàn)驗證

    SpringBoot+SpringSecurity+jwt實現(xiàn)驗證

    本文主要介紹了SpringBoot+SpringSecurity+jwt實現(xiàn)驗證,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-07-07
  • 教你如何寫springboot接口?

    教你如何寫springboot接口?

    這篇文章主要介紹了教你如何寫springboot接口,Spring?Boot是由Pivotal團隊提供的全新框架,其設計目的是用來簡化新Spring應用的初始搭建以及開發(fā)過程。該框架使用了特定的方式來進行配置,從而使開發(fā)人員不再需要定義樣板化的配置,需要的朋友可以參考y一下
    2022-01-01
  • 一文詳解Java中的動態(tài)填充Html模版并轉(zhuǎn)PDF

    一文詳解Java中的動態(tài)填充Html模版并轉(zhuǎn)PDF

    在后端技術(shù)中,模板引擎和PDF生成工具是兩個非常重要的領(lǐng)域,Thymeleaf和wkhtmltopdf是這兩個領(lǐng)域的杰出代表,下面就來詳細介紹一下Thymeleaf和wkhtmltopdf的技術(shù)特點吧
    2023-12-12
  • java繼承中的構(gòu)造方法實例解析

    java繼承中的構(gòu)造方法實例解析

    這篇文章主要介紹了java繼承中的構(gòu)造方法實例解析,針對繼承中的構(gòu)造方法的特點進行了實例分析,需要的朋友可以參考下
    2014-10-10

最新評論

岚皋县| 道真| 遵义县| 沈丘县| 蒲江县| 博乐市| 南充市| 吴堡县| 吴桥县| 云霄县| 涿鹿县| 奈曼旗| 长春市| 马边| 轮台县| 厦门市| 阆中市| 武邑县| 宁强县| 达州市| 察隅县| 玛曲县| 兰州市| 攀枝花市| 祁连县| 惠来县| 利辛县| 北辰区| 黄骅市| 广汉市| 加查县| 南丹县| 延长县| 怀柔区| 徐水县| 栖霞市| 墨江| 乌拉特中旗| 长岛县| 铜鼓县| 上林县|