java.util.Collections.unmodifiableSortedSet() 方法


java.util.Collections.unmodifiableSortedSet() 方法

package com.codingdict;

import java.util.*;

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

      // create sorted set
      SortedSet<String> set = new TreeSet<String>();

      // populate the set
      set.add("Welcome");
      set.add("to");
      set.add("TP");

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

      // create unmodifiable sorted set
      Set unmodsortset = Collections.unmodifiableSortedSet(set);

      // try to modify the sorted set
      unmodsortset.add("Hello");
   }
}