Java List Contain getListValue(Object container, int index)

Here you can find the source of getListValue(Object container, int index)

Description

get List Value

License

Open Source License

Declaration

public static Object getListValue(Object container, int index) 

Method Source Code

//package com.java2s;
/*//from w  w  w.  ja  v a  2 s  .  co  m
 * This file is part of the RUNA WFE project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; version 2.1
 * of the License.
 *
 * 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 */

import java.util.List;

public class Main {
    public static Object getListValue(Object container, int index) {
        if (container instanceof List) {
            List<?> list = (List<?>) container;
            if (list.size() > index) {
                return list.get(index);
            } else {
                throw new RuntimeException("List has insufficient size, index = " + index);
            }
        } else if (container.getClass().isArray()) {
            Object[] array = (Object[]) container;
            if (array.length > index) {
                return array[index];
            } else {
                throw new RuntimeException("Array has insufficient length, index = " + index);
            }
        } else {
            throw new RuntimeException(
                    "Unsupported array type " + (container != null ? container.getClass() : "null"));
        }
    }
}

Related

  1. containsType(List list, Class type)
  2. containsUnorderedSequence(List a, List b)
  3. containsUsingToArray(List list, Integer value)
  4. containsWhitespace(List elements)
  5. firstFunnyString(List words, String containedTest)
  6. identityContains(Object o, List list)
  7. indexOfLineContaining(List lines, String s)
  8. isContain(List list, Integer i)
  9. isContainedInAll(String keyToSearch, List> list)