日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

Java Collections list()方法与示例

發(fā)布時(shí)間:2023/12/1 java 57 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java Collections list()方法与示例 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

集合類(lèi)list()方法 (Collections Class list() method)

  • list() method is available in java.util package.

    list()方法在java.util包中可用。

  • list() method is used to return an array list that contains all the elements returned by the given Enumeration and the way of storing the elements in an ArrayList in the order as returned by the enumeration.

    list()方法用于返回一個(gè)數(shù)組列表,該列表包含給定Enumeration返回的所有元素,以及將這些元素按枚舉返回的順序存儲(chǔ)在ArrayList中的方式。

  • list() method is a static method, so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.

    list()方法是靜態(tài)方法,因此可以使用類(lèi)名進(jìn)行訪問(wèn),如果嘗試使用類(lèi)對(duì)象訪問(wèn)該方法,則不會(huì)收到錯(cuò)誤。

  • list() method does not throw an exception at the time of conversion of the given Enumeration to an Arraylist.

    在將給定的枚舉轉(zhuǎn)換為Arraylist時(shí), list()方法不會(huì)引發(fā)異常。

Syntax:

句法:

public static Arraylist list(Enumeration en);

Parameter(s):

參數(shù):

  • Enumeration en – represents the Enumeration that pass all the elements for the returned ArrayList.

    Enumeration en –表示為返回的ArrayList傳遞所有元素的Enumeration。

Return value:

返回值:

The return type of this method is ArrayList, it returns an ArrayList of the given Enumeration.

此方法的返回類(lèi)型為ArrayList ,它返回給定Enumeration的ArrayList。

Example:

例:

// Java program is to demonstrate the example // of ArrayList list() of Collectionsimport java.util.*;public class ListOfCollections {public static void main(String args[]) {// Instantiate an ArrayList and // Stack objectList arr_l = new ArrayList();Stack st = new Stack();// By using push() method is// to add elements in stackst.push(10);st.push(20);st.push(30);st.push(40);st.push(50);// Get elements in an enumeration objectEnumeration en = st.elements();// By using list() method is to // return the array list of the // given enumeration objectarr_l = Collections.list(en);System.out.println("Collections.list(en): " + arr_l);} }

Output

輸出量

Collections.list(en): [10, 20, 30, 40, 50]

翻譯自: https://www.includehelp.com/java/collections-list-method-with-example.aspx

總結(jié)

以上是生活随笔為你收集整理的Java Collections list()方法与示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。