Results 1 to 2 of 2
  1. #1
    java4amanda is offline Member
    Join Date
    Jan 2012
    Rep Power

    Default 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>();



    for(String s : al)







    Now is the above code valid

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Synchronized ArrayList

    The return value of the Collections.synchronizedList( ... ) method is a synchronized list, but you're not using it at all.

    kind regards,

    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. synchronized(this){}
    By zserzs in forum Threads and Synchronization
    Replies: 6
    Last Post: 03-21-2012, 03:08 AM
  2. Replies: 12
    Last Post: 07-07-2011, 08:49 PM
  3. Replies: 1
    Last Post: 09-08-2010, 04:08 PM
  4. Synchronized(this)?
    By kiza in forum Threads and Synchronization
    Replies: 10
    Last Post: 04-07-2009, 01:20 PM
  5. synchronized
    By bugger in forum New To Java
    Replies: 2
    Last Post: 11-28-2007, 11:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts