Create an unmodifiable Map - Java java.util

Java examples for java.util:Collection Creation

Description

Create an unmodifiable Map

Demo Code


//package com.java2s;

import java.util.Collections;

import java.util.Map;

public class Main {
    /**//from w ww. ja  va  2  s  . com
     * @return an <b>UNMODIFIABLE</b> Map&lt;K, V&gt;
     */
    public static <K, V> Map<K, V> unmodifiableMap(
            final Map<? extends K, ? extends V> m) {
        return (m == null) ? Collections.<K, V> emptyMap() : Collections
                .unmodifiableMap(m);
    }
}

Related Tutorials