首页javasetJava Collection - 如何将Set设置为Synchronized Set

Java Collection - 如何将Set设置为Synchronized Set

我们想知道如何将Set设置为Synchronized Set。
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class Main {
  public static void main(String[] args) {
    HashSet hashSet = new HashSet();
    Set set = Collections.synchronizedSet(hashSet);
    System.out.println(set);
  }
}