Java Collection Element Get getAt(Collection col, int index)

Here you can find the source of getAt(Collection col, int index)

Description

get At

License

Open Source License

Declaration

public static <T> T getAt(Collection<T> col, int index) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

import java.util.Iterator;

import java.util.List;

public class Main {
    public static <T> T getAt(Collection<T> col, int index) {
        if (col instanceof List)
            return ((List<T>) col).get(index);
        int i;/*w ww .j  a va  2 s.c o  m*/
        Iterator<T> it;
        for (i = 0, it = col.iterator(); i < index && it.hasNext(); it.next())
            ;
        return it.hasNext() ? it.next() : null;
    }
}

Related

  1. GetArrayFromCollection(java.util.Collection col)
  2. getArrays(Object parent, Collection collection)
  3. getAssociationCollectionObjectName(Collection currentObjectColl, Collection prevObjectColl)
  4. getAsString(Collection data, char seperator)
  5. getAsString(Collection input)
  6. getAuthzNameFromEntityName(String entityName, Collection authzProvidersNames)
  7. getByIndex(Collection availableTransitions, int index)
  8. getByIndex(Collection vals, int idx)
  9. getByMostFrequent(Collection collection)

  10. HOME | Copyright © www.java2s.com 2016