Java examples for java.util:Map Value
Gets a value from a map of maps.
/*//from w w w.j av a 2 s. co m * Copyright 2013 Anton Karmanov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ //package com.java2s; import java.util.Map; public class Main { /** * Gets a value from a map of maps. * * @param map1 the map of maps. * @param key1 the key for the map of maps. * @param key2 the key for a nested map. * @return the value, or <code>null</code> if the key is not found neither in the outer, * nor in the nested map. */ static <K1, K2, V> V getFromMapMap(Map<K1, Map<K2, V>> map1, K1 key1, K2 key2) { Map<K2, V> map2 = map1.get(key1); return map2 == null ? null : map2.get(key2); } }