描述
该synchronizedSortedSet()方法用于获取的同步(thread-safe)有序set由指定有序set支持。
声明
以下是java.util.Collections.synchronizedSortedSet()方法的声明。
public static SortedSet synchronizedSortedSet(SortedSet 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 set = new TreeSet();
// 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]