Top Description Constructors Methods
org.apache.commons.collections4

public Class EnumerationUtils

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Enumeration, .List, .StringTokenizer, org.apache.commons.collections4.iterators.EnumerationIterator

Provides utility methods for Enumeration instances.
Since
3.0

Constructor Summary

AccessConstructor and Description
private
EnumerationUtils()

EnumerationUtils is not normally instantiated.

Method Summary

Modifier and TypeMethod and Description
public static <
the type of object in the Enumeration
T
>
T

Returns:

the object at the specified index
get
(final Enumeration<T>
the enumeration to get a value from
e
,
final int
the index to get
index
)

Returns the index-th value in the Enumeration, throwing IndexOutOfBoundsException if there is no such element.

public static <
the element type
E
>
List<E>

Returns:

a list containing all elements of the given enumeration
toList
(final Enumeration<? extends E>
the enumeration to traverse, which should not be null.
enumeration
)

Creates a list based on an enumeration.

public static List<String>

Returns:

a list containing all tokens of the given StringTokenizer
toList
(final StringTokenizer
the tokenizer to convert to a List<String>
stringTokenizer
)

Override toList(Enumeration) for StringTokenizer as it implements Enumeration<Object> for the sake of backward compatibility.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EnumerationUtilsback to summary
private EnumerationUtils()

EnumerationUtils is not normally instantiated.

Method Detail

getback to summary
public static <T> T get(final Enumeration<T> e, final int index)

Returns the index-th value in the Enumeration, throwing IndexOutOfBoundsException if there is no such element.

The Enumeration is advanced to index (or to the end, if index exceeds the number of entries) as a side effect of this method.

Parameters
<T>
the type of object in the Enumeration
e:Enumeration<T>

the enumeration to get a value from

index:int

the index to get

Returns:T

the object at the specified index

Exceptions
IndexOutOfBoundsException:
if the index is invalid
IllegalArgumentException:
if the object type is invalid
Since
4.1
toListback to summary
public static <E> List<E> toList(final Enumeration<? extends E> enumeration)

Creates a list based on an enumeration.

As the enumeration is traversed, an ArrayList of its values is created. The new list is returned.

Parameters
<E>
the element type
enumeration:Enumeration<? extends E>

the enumeration to traverse, which should not be null.

Returns:List<E>

a list containing all elements of the given enumeration

Exceptions
NullPointerException:
if the enumeration parameter is null.
toListback to summary
public static List<String> toList(final StringTokenizer stringTokenizer)

Override toList(Enumeration) for StringTokenizer as it implements Enumeration<Object> for the sake of backward compatibility.

Parameters
stringTokenizer:StringTokenizer

the tokenizer to convert to a List<String>

Returns:List<String>

a list containing all tokens of the given StringTokenizer