Fundamentals

Default Methods

Collections

Idioms and Techniques

Design Rationale

Advanced Questions

How can I turn an Iterator into a List?

There is a convenience method on the Collections class:

public static ArrayList list(Enumeration e)

This works for the old Enumeration type, but it seems to be a glaring omission that there is no similar method for an Iterator. Certainly one could write a loop:

while (iterator.hasNext()) { list.add(iterator.next()); }

Unfortunately it’s not possible to use […]