Java Collection Element Get get(Collection coll, int index)

Here you can find the source of get(Collection coll, int index)

Description

get

License

MIT License

Declaration

public static Object get(Collection coll, int index) 

Method Source Code

//package com.java2s;
/**/*from  www  .  j av a  2s. c o m*/
 * Copyright (c) 2004-2011 Wang Jinbao(Julian Wong), http://www.ralasafe.com
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 */

import java.util.Collection;

import java.util.Iterator;

import java.util.List;

public class Main {
    public static Object get(Collection coll, int index) {
        if (coll instanceof List) {
            return ((List) coll).get(index);
        } else {
            int i = 0;
            for (Iterator iter = coll.iterator(); iter.hasNext();) {
                Object object = (Object) iter.next();
                if (i == index) {
                    return object;
                }

                i++;
            }
        }

        return null;
    }
}

Related

  1. get(Collection p_collection, int p_index)
  2. get(Collection arr, int idx)
  3. get(Collection collection, int index)
  4. get(Collection p_oCol, T p_oObj)