Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.HashMap;

import java.util.Map;

public class Main {
    public static <K1, K2, V> Map<K2, V> mapGetOrCreateMap(Map<K1, Map<K2, V>> mapOfMaps, K1 firstKey) {
        Map<K2, V> m = mapOfMaps.get(firstKey);
        if (null == m) {
            m = newMap();
            mapOfMaps.put(firstKey, m);
        }
        return m;
    }

    public static <K, V> Map<K, V> newMap() {
        return new HashMap<K, V>();
    }

    public static <K, V> Map<K, V> newMap(int initCap) {
        return new HashMap<K, V>(initCap);
    }
}