Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: safe collection operation

Java: safe collection operation
{filelink=10865}

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class CollectionSafeIteration extends Object
{
  public static void main(String[] args)
  	{
  	// create a synchronized ArrayList
    List arrayL = Collections.synchronizedList(new ArrayList());
    for(char x='a'; x<='z'; x+=1)
    	arrayL.add(x);
    // Iterate through  ArrayList
    synchronized (arrayL)
    {
      Iterator iter = arrayL.iterator();
      while (iter.hasNext()) {
        Character lettre = (Character) iter.next();
        System.out.println(lettre);
      }
    }
  }
}

No comments yet.

Leave a Comment