Java Utililty Methods Collection Element Get

List of utility methods to do Collection Element Get

Description

The list of methods to do Collection Element Get are organized into topic(s).

Method

TgetHighest(final Collection elements, final Comparator c)
Retrieve highest element contained in a collection.
return Collections.max(elements, c);
ClassgetImplement(Class aClass, Collection> classCollection)
get Implement
for (Class<?> c : classCollection) {
    if (c.isAssignableFrom(aClass)) {
        return c;
return null;
ObjectgetIndex(Object collectionOrArray, int index)
get Index
if (collectionOrArray instanceof Collection) {
    return getIndex((Collection) collectionOrArray, index);
} else if (collectionOrArray.getClass().isArray()) {
    return ((Object[]) collectionOrArray)[index];
} else {
    throw new IllegalArgumentException(String.format(
            "Don't know how to treat object of type '%1$s' as an array", collectionOrArray.getClass()));
ObjectgetIndexedValue(Object collection, int index)
get Indexed Value
Object result = null;
if (collection instanceof Object[]) {
    Object[] x = (Object[]) collection;
    if (index < x.length) {
        return x[index];
} else if (collection instanceof Collection) {
    Collection<?> x = (Collection<?>) collection;
...