Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.Map;

public class Main {
    /**
     * Get the value from the map for the given key. It the value does not exist, return the given
     * defaultValue.
     *
     * @param <K>          key type
     * @param <V>          value type
     * @param map          map
     * @param key          key
     * @param defaultValue default value if the value is null.
     * @return value
     */
    public static <K, V> V getValue(Map<K, V> map, K key, V defaultValue) {
        V v = map.get(key);
        if (v == null) {
            return defaultValue;
        }
        return v;
    }
}