Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Get Enumeration over ArrayList with Java Collections



In order to get enumeration over ArrayList with Java Collections, we use the java.util.Collections.enumeration() method.

Declaration −The java.util.Collections.enumeration() method is declared is as follows −

public static <T> Enumeration<T> enumeration(Collection<T> c)

where c is the collection object for which an enumeration is returned

Let us see a program to get enumeration over ArrayList −

Example

 Live Demo

import java.util.*;
public class Example {
   public static void main (String[] args) {
      ArrayList<Integer> list = new ArrayList<Integer>();
      list.add(14);
      list.add(2);
      list.add(73);
      Enumeration en = Collections.enumeration(list); // getting enumeration over ArrayList list
      while(en.hasMoreElements()) {
         System.out.println(en.nextElement());
      }
   }
}

Output

14
2
73
Updated on: 2020-06-25T14:36:46+05:30

598 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements