Friday, October 31, 2014

Java Synchronized List Pro



Get Synchronized List from Java Array List

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class GetSynchronizedListFromArrayListExample
 {
public static void main(String[] args)
{
ArrayList arrayList = new ArrayList();
List list = Collections.synchronizedList(arrayList);
    }
}

Get Synchronized Map from Java Hash Map

import java.util.HashMap;
import java.util.Collections;
import java.util.Map;
public class GetSynchronizedMapFromHashMapExample
 {
public static void main(String[] args)
{
HashMap hashMap = new HashMap(); Map map = Collections.synchronizedMap(hashMap);
   }
}

Get Synchronized Map from Java Tree Map

import java.util.TreeMap;
import java.util.Collections;
import java.util.Map;
public class GetSynchronizedMapFromTreeMapExample
{
 public static void main(String[] args)
{
TreeMap treeMap = new TreeMap();
 Map map = Collections.synchronizedMap(treeMap);
    }
}

Get Synchronized Set from Java Hash Set

import java.util.HashSet;
import java.util.Collections;
import java.util.Set;
public class GetSynchronizedSetFromHashSetExample
{
 public static void main(String[] args)
{
HashSet hashSet = new HashSet();
Set set = Collections.synchronizedSet(hashSet);
    }
}

No comments:

Post a Comment