Getting an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration.

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

package collection.demos;



import java.util.ArrayList;

import java.util.Collections;

import java.util.Enumeration;



public class GettingListOfEnumeration{



    public static void main(String[] args) {

        ArrayList<String> list = new ArrayList<String>();

        list.add("A");

        list.add("B");

        list.add("C");

        list.add("D");

        Enumeration<String> e=Collections.enumeration(list);

       ArrayList<String> list2=Collections.list(e);

        System.out.println("List : "+list2);

    }

}

/*

OUTPUT : 

List : [A, B, C, D]

 */

No comments:

Popular Posts