Sync Test : Set : Collections Data Structure : Java examples (example source code) Organized by topic

Java
C++
PHP
Java Home »  Collections Data Structure   » [  Set  ]  Screenshots 
 



Sync Test



import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class SyncTest {
  public static void main(String args[]) {
    Set simpsons = new HashSet();
    simpsons.add("Bart");
    simpsons.add("Hugo");
    simpsons.add("Lisa");
    simpsons.add("Marge");
    simpsons.add("Homer");
    simpsons.add("Maggie");
    simpsons.add("Roy");
    simpsons = Collections.synchronizedSet(simpsons);
    synchronized (simpsons) {
      Iterator iter = simpsons.iterator();
      while (iter.hasNext()) {
        System.out.println(iter.next());
      }
    }
    Map map = Collections.synchronizedMap(new HashMap(89));
    Set set = map.entrySet();
    synchronized (map) {
      Iterator iter = set.iterator();
      while (iter.hasNext()) {
        System.out.println(iter.next());
      }
    }
  }
}

           
       
Related examples in the same category
1.  Things you can do with Sets Things you can do with Sets
2.  Putting your own type in a Set Putting your own type in a Set
3.  Use set Use set
4.  Another Set demo
5.  Set substraction Set substraction
6.  Working with HashSet and TreeSet Working with HashSet and TreeSet
7.  TreeSet Demo TreeSet Demo
8.  Show the union and instersection of two sets
9.  Demonstrate the Set interface
10.  TreeSet Test
11.  Array Set extends AbstractSet Array Set extends AbstractSet
12.  Set Copy
13.  Set and TreeSet
14.  Tail
15.  What you can do with a TreeSet What you can do with a TreeSet
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.