Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.Map;

public class Main {
    public static <K, V> V safeGet(Map<K, V> map, K key, V defaultValue) {
        if (map == null) {
            return null;
        } else {
            return map.containsKey(key) ? map.get(key) : defaultValue;
        }
    }

    public static <K, V> V safeGet(Map<K, V> map, K key) {
        if (map == null) {
            return null;
        } else {
            return map.containsKey(key) ? map.get(key) : null;
        }
    }
}