Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class Main {

    public static <K, V> V getValueByIndex(LinkedHashMap<K, V> map, int index) {
        if (index <= -1) {
            return null;
        }
        List<V> valueList = getValueListByIndexes(map, new int[] { index });
        if ((valueList != null) && (valueList.size() > 0)) {
            return valueList.get(0);
        }
        return null;
    }

    public static <K, V> List<V> getValueListByIndexes(Map<K, V> map, int[] indexes) {
        if ((indexes == null) || (indexes.length == 0)) {
            return null;
        }
        List<V> valueList = new ArrayList<V>(indexes.length);
        int i = 0;
        for (V value : map.values()) {
            for (int index : indexes) {
                if (i == index) {
                    valueList.add(value);
                }
            }
            i++;
        }
        return valueList;
    }
}