Java Collection Element Get get(final Collection list, final int pos)

Here you can find the source of get(final Collection list, final int pos)

Description

get

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <T extends Object> T get(final Collection<? extends Object> list, final int pos) 

Method Source Code


//package com.java2s;
/*/*w w w  .j  ava  2s .  com*/
 * Copyright (C) 2010 by Tobias Buchloh.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this program; if not, write to the Free
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * If you didn't download this code from the following link, you should check if
 * you aren't using an obsolete version:
 * http://www.sourceforge.net/projects/KisKis
 */

import java.util.Collection;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T extends Object> T get(final Collection<? extends Object> list, final int pos) {
        int cnt = 0;
        for (final Object group : list) {
            if (cnt == pos) {
                return (T) group;
            }
            cnt += 1;
        }
        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)
  5. get(Collection v, int i)
  6. get(final Collection collection, final int index)
  7. getAddedItems(Collection oldValues, Collection newValues)
  8. getAdditions(Collection source, Collection target)
  9. getAll(Map map, Collection indices)