Collections list() method in Java with Examples Last Updated : 15 May, 2019 Comments Improve Suggest changes Like Article Like Report The list() method of java.util.Collections class is used to return an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration. This method provides interoperability between legacy APIs that return enumerations and new APIs that require collections. Syntax: public static ArrayList list(Enumeration e) Parameters: This method takes enumeration e as a parameter providing elements for the returned array list. Return Value: This method returns an array list containing the elements returned by the specified enumeration. Below are the examples to illustrate the list() method Example 1: Java // Java program to demonstrate // list() method // for String value import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { try { // creating object of List<String> List<String> arrlist = new ArrayList<String>(); // creating object of Vector<String> Vector<String> v = new Vector<String>(); // Adding element to Vector v v.add("A"); v.add("B"); v.add("C"); v.add("D"); v.add("E"); // printing the list System.out.println("Current list : " + arrlist); // creating Enumeration Enumeration<String> e = v.elements(); // getting arrlist of specified Enumeration // using list() method arrlist = Collections.list(e); // printing the arrlist System.out.println("Returned list: " + arrlist); } catch (IllegalArgumentException e) { System.out.println("Exception thrown : " + e); } } } Output: Current list : [] Returned list: [A, B, C, D, E] Example 2: Java // Java program to demonstrate // list() method // for Integer value import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { try { // creating object of List<String> List<Integer> arrlist = new ArrayList<Integer>(); // creating object of Vector<String> Vector<Integer> v = new Vector<Integer>(); // Adding element to Vector v v.add(10); v.add(20); v.add(30); v.add(40); v.add(50); // printing the list System.out.println("Current list : " + arrlist); // creating Enumeration Enumeration<Integer> e = v.elements(); // getting arrlist of specified Enumeration // using list() method arrlist = Collections.list(e); // printing the arrlist System.out.println("Returned list: " + arrlist); } catch (IllegalArgumentException e) { System.out.println("Exception thrown : " + e); } } } Output: Current list : [] Returned list: [10, 20, 30, 40, 50] Comment More infoAdvertise with us Next Article Collections list() method in Java with Examples rohitprasad3 Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions +1 More Practice Tags : JavaJava-CollectionsMisc Similar Reads Collections max() method in Java with Examples max(Collection<? extends T> coll) The max() method of java.util.Collections class is used to return the maximum element of the given collection, according to the natural ordering of its elements. All elements in the collection must implement the Comparable interface. Furthermore, all elements 5 min read List contains() method in Java with Examples The contains() method of List interface in Java is used for checking if the specified element exists in the given list or not. Example:Java// Java Program to Demonstrate // List contains() Method import java.util.*; class GFG { public static void main (String[] args) { List<Integer> l = new Ar 3 min read Collections min() method in Java with Examples min(Collection<? extends T> coll) The min() method of java.util.Collections class is used to return the minimum element of the given collection, according to the natural ordering of its elements. All elements in the collection must implement the Comparable interface. Furthermore, all elements 4 min read Collection add() Method in Java with Examples The add(E element) of java.util.Collection interface is used to add the element 'element' to this collection. This method returns a boolean value depicting the successfulness of the operation. If the element was added, it returns true, else it returns false. Syntax: Collection.add(E element) Paramet 4 min read Collections fill() method in Java with Examples The fill() method of java.util.Collections class is used to replace all of the elements of the specified list with the specified element. This method runs in linear time. Syntax: public static void fill(List list, T obj) Parameters: This method takes following argument as parameter list - the list t 2 min read List containsAll() method in Java with Examples The containsAll() method of List interface in Java is used to check if this List contains all of the elements in the specified Collection. So basically it is used to check if a List contains a set of elements or not. Syntax: boolean containsAll(Collection col) Parameters: This method accepts a manda 2 min read Collection clear() method in Java with Examples The collection clear() method of Java Collection Interface clears the Collection upon which it is called. After this method is called, the collection will be empty as it removes all the elements from the collection. This method does not take any parameter and does not return any value. Example: Java 3 min read Collections addAll() method in Java with Examples The addAll() method of java.util.Collections class is used to add all of the specified elements to the specified collection. Elements to be added may be specified individually or as an array. The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this 3 min read Collection addAll() method in Java with Examples The addAll(Collection collection) of java.util.Collection interface is used to add the Collection 'collection' to this existing collection. This method returns a boolean value depicting the successfulness of the operation. If the collection was added, it returns true, else it returns false. Syntax: 3 min read Collection contains() method in Java with Examples The contains(Object element) of java.util.Collection interface is used to check whether the element 'element' exists in this collection. This method returns a boolean value depicting the presence of the element. If the element is present, it returns true, else it returns false. Syntax: Collection.co 3 min read Like