Collections static ArrayList list(Enumeration e) method Example Program


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

Program

package com.candidjava;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;

/**
 * 
 * @author karthikeyan.T
 * @description In the following code shows how to use
 *              Collections.list(Enumeration <T> e) method.
 */
public class ListEnumeration {

	public static void main(String args[]) {
		List<String> arrlist = new ArrayList<String>();
		Vector<String> v = new Vector<String>();
		v.add("karthik");
		v.add("kamal");
		v.add("mohan");
		v.add("vinodh");
		v.add("hari");
		v.add("anand");
		Enumeration<String> e = v.elements();
		arrlist = Collections.list(e);
		System.out.println("Value of returned list: " + arrlist);
	}
}

Output

Value of returned list: [karthik, kamal, mohan, vinodh, hari, anand]

Explanation

public static <T> ArrayList<T> list(Enumeration<T> e)
Returns 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.
Parameters:
e - enumeration providing elements for the returned array list
Returns:
an array list containing the elements returned by the specified enumeration.
Since:
1.4
See Also:
Enumeration, ArrayList


Related Post

Comments


©candidjava.com