Home » Java programming language

Java Collections list() Method with Example

Collections Class list() method: Here, we are going to learn about the list() method of Collections Class with its syntax and example.
Submitted by Preeti Jain, on February 04, 2020

Collections Class list() method

  • list() method is available in java.util package.
  • 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() 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() method does not throw an exception at the time of conversion of the given Enumeration to an Arraylist.


    public static Arraylist list(Enumeration en);


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

Return value:

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


// Java program is to demonstrate the example
// of ArrayList list() of Collections

import 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

        // 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);


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

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.