java.util.Collections.synchronizedSortedSet() 方法
描述
synchronizedSortedSet() 方法用于获取由指定排序集支持的同步(线程安全)排序集。
声明
以下是 java.util.Collections.synchronizedSortedSet() 方法的声明。
public static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s)
参数
s − 这是要"包装"在同步排序集中的排序集。
返回值
方法调用返回指定排序集的同步视图。
异常
NA
示例
下面的例子展示了 java.util.Collections.synchronizedSortedSet() 的用法。
package com.tutorialspoint; 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]