Collections: Collections.list bridges a legacy Enumeration into an ArrayList

Collections.list drains an old-style Enumeration, such as Vector.elements(), into a brand-new ArrayList, giving legacy APIs a clean way to hand data to modern List-based code.

Code
Vector<String> legacy = new Vector<>(List.of("alpha", "beta", "gamma"));
Enumeration<String> e = legacy.elements();
List<String> modern = Collections.list(e);
System.out.println("Bridged into a List: " + modern);
System.out.println("Type: " + modern.getClass().getSimpleName());
Output
Bridged into a List: [alpha, beta, gamma]
Type: ArrayList
Advertisement
More in JAVA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-09-27

© Java Coding Hub · About · Contact · Privacy · Terms