java.util.Collections.unmodifiableSortedMap() 方法


java.util.Collections.unmodifiableSortedMap() 方法

package com.codingdict;

import java.util.*;

public class CollectionsDemo {
   public static void main(String[] s) {

      // create sorted map
      SortedMap<String,String> map = new TreeMap<String, String>();

      // populate the set
      map.put("1","New");
      map.put("2","to");
      map.put("3","TP");

      System.out.println("Initial sorted map value: "+map);

      // create unmodifiable sorted map
      Map unmodsortmap = Collections.unmodifiableSortedMap(map);

      // try to modify the sorted map
      unmodsortmap.put("4","Modify");
   }
}