1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
/* Get Synchronized Set from Java TreeSet example This java example shows how to get a synchronized Set from Java TreeSet using synchronizedSet method of Collections class. */ import java.util.TreeSet; import java.util.Collections; import java.util.Set; public class GetSynchronizedSetFromTreeSetExample { public static void main(String[] args) { //create TreeSet object TreeSet treeSet = new TreeSet(); /* Java TreeSet is NOT synchronized. To get synchronized Set from TreeSet use static void synchronizedSet(Set set) method of Collections class. */ Set set = Collections.synchronizedSet(treeSet); /* Use this set object to prevent any unsynchronized access to original TreeSet object. */ } } |
Add Comment