Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Java Synchronized ArrayList

By default, ArrayList object is not synchronized. This Java example shows how to get Synchronized ArrayList.
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3.  
  4. //Java Synchronized ArrayList
  5.  
  6. public class JavaSynchronizedArrayList {
  7.    
  8.     public static void main(String args[]){
  9.        
  10.         /*
  11.          * By default, ArrayList object is not synchronized. That means it is not
  12.          * thread safe. We need synchronized ArrayList if it is being modified
  13.          * by multiple threads at a time.
  14.          *
  15.          * To get synchronized ArrayList, use
  16.          * Collections.synchronizedList(List list) method.
  17.          */
  18.        
  19.         //this will give us synchronized ArrayList object
  20.         ArrayList aListCounter = (ArrayList) Collections.synchronizedList(new ArrayList());
  21.     }
  22. }
No votes yet
Share this
Anonymous's picture

ok not bad

ok not bad
Anonymous's picture

All The Best Deepu....

All The Best Deepu....
Anonymous's picture

post some of your innovative

post some of your innovative ideas not copy-paste things from others and already published materials.
Anonymous's picture

it's good but i want to say

it's good but i want to say to you that it's all are simple type programs. you need to provide some more useful data.

Post new comment

6 + 5 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.