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.Iterator;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class Main {

    public static <K, V> List<K> getKeyListByValues(Map<K, V> map, V[] values) {
        if ((values == null) || (values.length == 0)) {
            return null;
        }
        List<K> keyList = new ArrayList<K>(map.size());
        Set<Map.Entry<K, V>> entrySet = map.entrySet();
        for (Iterator<?> localIterator = entrySet.iterator(); localIterator.hasNext();) {
            Map.Entry<K, V> entry = (Map.Entry) localIterator.next();

            for (int i = 0; i < values.length; i++) {
                Object value = values[i];
                if ((entry.getValue() == null)
                        || ((entry.getValue() != null) && (entry.getValue().equals(value)))) {
                    keyList.add(entry.getKey());
                }
            }
        }
        return keyList;
    }
}