synchronizedSortedSet() 方法用于获得同步的(线程安全的)有序set由指定的有序set支持。
声明
以下是 java.util.Collections.synchronizedSortedSet()方法的声明。
public static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s)
参数
-
s--这是一个有序集合被“包装”在同步有序set。
返回值
-
在方法调用返回指定有序set的同步视图。
异常
-
NA
例子
下面的例子显示java.util.Collections.synchronizedSortedSet()方法的使用
package com.yiibai; import java.util.*; public class CollectionsDemo { public static void main(String[] args) { // create set SortedSet<String> set = new TreeSet<String>(); // populate the set set.add("TP"); set.add("IS"); set.add("FOR"); set.add("TECHIES"); // create a synchronized sorted set SortedSet sorset = Collections.synchronizedSortedSet(set); System.out.println("Sorted set is :"+sorset); } }
现在编译和运行上面的代码示例,将产生以下结果。
Sorted set is :[FOR, IS, TECHIES, TP]