unmodifiableSortedSet()%uA0方法用于获取指定有序set的不可修改视图。
声明
以下是java.util.Collections.unmodifiableSortedSet()方法的声明。
public static <T> SortedSet <T> unmodifiableSortedSet(SortedSet <T> s)
参数
-
s--这是有序set的一个不可修改视图将被返回。
返回值
在方法调用返回指定有序set的不可修改视图。
异常
-
NA
例子
下面的例子显示java.util.Collections.unmodifiableSortedSet()方法的使用
package com.yiibai 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") } }
现在编译和运行上面的代码示例,将产生以下结果。
Initial set value: [TP, Welcome, to] Exception in thread "main" java.lang.UnsupportedOperationException