Java Map create an unmodifiable map

Description

Java Map create an unmodifiable map

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class Main {

  public static void main(String[] args) {
    Map<String, String> map = createUnmodifiableMap();
    map.put("CSS", "style");
  }/*from   w w w .  java2  s  .c  om*/

  public static final Map<String, String> createUnmodifiableMap() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("HTML", "mark");
    return Collections.unmodifiableMap(map);
  }
}



PreviousNext

Related