Results 1 to 2 of 2
Thread: Synchronized ArrayList
- 05-08-2012, 11:05 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 55
- Rep Power
- 0
Synchronized ArrayList
Hi All,
Can anyone kindly tell me how to create a synchronized arraylist? Below mentioned is a line of code that i bumped into some site while searching about how to synchronize an array list'
List<String> syncList = Collections.synchronizedList(new ArrayList<String>());.
But when i tried using that code i faced compile time error >>> incompatible types.
I tried the below code on my own and kindly tell me will it work?
import java.util.*;
class AList
{
public static void main(String[] agrs)
{
ArrayList <String> al = new ArrayList<String>();
al.add("john");
al.add("max");
for(String s : al)
{
Collections.synchronizedList(s);
System.out.println(s);
}
}
}
Now is the above code valid
- 05-08-2012, 11:56 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
synchronized(this){}
By zserzs in forum Threads and SynchronizationReplies: 6Last Post: 03-21-2012, 02:08 AM -
ArrayList copy some of the element from one arraylist tnto another arraylist
By ralf in forum New To JavaReplies: 12Last Post: 07-07-2011, 08:49 PM -
Difference b/w "synchronized","synchronize",and "synchronized()"
By Bala_Rugan in forum New To JavaReplies: 1Last Post: 09-08-2010, 04:08 PM -
Synchronized(this)?
By kiza in forum Threads and SynchronizationReplies: 10Last Post: 04-07-2009, 01:20 PM -
synchronized
By bugger in forum New To JavaReplies: 2Last Post: 11-28-2007, 10:33 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks