Collections.list(Enumeration): This method is available in java.util.Collections class of Java.
Syntax:
<E> ArrayList<Integer> java.util.Collections.list(Enumeration<E> e)
This method takes one argument. This method returns an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration.
Parameters: One parameter is required for this method.
e: enumeration providing elements for the returned array list.
Returns: an array list containing the elements returned by the specified enumeration.
Exceptions: NA
Approach
Java
import java.util.ArrayList;import java.util.Collections;import java.util.Enumeration;import java.util.List;import java.util.Vector;public class Collectionslist {public static void main(String[] args) {List<Integer> arrlist = new ArrayList<Integer>();arrlist.add(12);Vector<Integer> vector = new Vector<Integer>();vector.add(10);vector.add(2);vector.add(5);vector.add(6);Enumeration<Integer> enumeration = vector.elements();System.out.println(Collections.list(enumeration));}}
Output:
[10, 2, 5, 6]
No comments:
Post a Comment