欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java使用同步集合,java同步集合,package cn.o

来源: javaer 分享于  点击 219 次 点评:210

java使用同步集合,java同步集合,package cn.o


package cn.outofmemory.snippets.core;import java.util.Collections;import java.util.HashSet;import java.util.Set;public class SynchronizedSetExample {  public static void main(String[] args) {    /*      Please note that the same API applies to any type of       Set implementation class e.g. TreeSet etc    */    // Create a HashSet and populate it with elements    HashSet hashSet = new HashSet();    hashSet.add("element_1");    hashSet.add("element_2");    hashSet.add("element_3");    // static void synchronizedSet(Set set) method returns a synchronized Set from HashSet    Set syncSet = Collections.synchronizedSet(hashSet);    System.out.println("syncSet contains : " + syncSet);  }}

输出:

syncSet contains : [element_1, element_2, element_3]
相关栏目:

用户点评