博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java Collections list()方法与示例
阅读量:2528 次
发布时间:2019-05-11

本文共 2018 字,大约阅读时间需要 6 分钟。

集合类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()方法用于返回一个数组列表,该列表包含给定Enumeration返回的所有元素,以及将这些元素按枚举返回的顺序存储在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()方法是静态方法,因此可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。

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

    在将给定的枚举转换为Arraylist时, list()方法不会引发异常。

Syntax:

句法:

public static Arraylist list(Enumeration en);

Parameter(s):

参数:

  • 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.

此方法的返回类型为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 object List arr_l = new ArrayList(); Stack st = new Stack(); // By using push() method is // to add elements in stack st.push(10); st.push(20); st.push(30); st.push(40); st.push(50); // Get elements in an enumeration object Enumeration en = st.elements(); // By using list() method is to // return the array list of the // given enumeration object arr_l = Collections.list(en); System.out.println("Collections.list(en): " + arr_l); }}

Output

输出量

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

翻译自:

转载地址:http://fexzd.baihongyu.com/

你可能感兴趣的文章
【转】判断点在多边形内(matlab)
查看>>
java基础之集合:List Set Map的概述以及使用场景
查看>>
Python 线程 进程 协程
查看>>
骨牌覆盖问题
查看>>
iOS语言中的KVO机制
查看>>
excel第一次打开报错 向程序发送命令时出错 多种解决办法含终极解决方法
查看>>
响应式web设计之CSS3 Media Queries
查看>>
实验三
查看>>
机器码和字节码
查看>>
环形菜单的实现
查看>>
Python 函数参数 传引用还是传值
查看>>
【解决Chrome浏览器和IE浏览器上传附件兼容的问题 -- Chrome关闭flash后,uploadify插件不可用的解决办法】...
查看>>
34 帧动画
查看>>
二次剩余及欧拉准则
查看>>
Centos 7 Mysql 最大连接数超了问题解决
查看>>
thymeleaf 自定义标签
查看>>
关于WordCount的作业
查看>>
C6748和音频ADC连接时候的TDM以及I2S格式问题
查看>>
UIView的layoutSubviews,initWithFrame,initWithCoder方法
查看>>
STM32+IAP方案 实现网络升级应用固件
查看>>