Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1024805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:49:58+00:00 2026-05-16T11:49:58+00:00

Vector is synchronized, ArrayList is not synchronized but we can synchronize an ArrayList by

  • 0

Vector is synchronized, ArrayList is not synchronized but we can synchronize an ArrayList by Collections.synchronizedList(aList), so which will perform better and faster?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:49:59+00:00Added an answer on May 16, 2026 at 11:49 am

    Synchronized collections are a waste of time and dangerous. A trivial example why they are bad is to consider two threads running a loop at the same time on the same collection:

    int i = 0;
    while (i < list.size())
    {
      if (testSomeCondition(list.get())) {
        list.remove(i);
      else
        i++;
    }
    

    Our list could be synchronized (e.g. a Vector) and this code would still break horribly. Why? Because the individual calls to size(), get(), remove(), are synchronized but one thread could still be removing items from the list while the other is iterating over it. In other words we have a race condition and the use of synchronized collections has gained us nothing.

    To fix the race we have to synchronize the entire operation on the collection or use Java 5 concurrency Locks to do the same.

    synchronized (list) {
      int i = 0;
      while (i < list.size())
      {
        if (testSomeCondition(list.get())) {
          list.remove(i);
        else
          i++;
      }
    }
    

    This block of code is now thread safe since only one thread can execute the loop at a time. And now there is no reason to use a synchronized collection. We can use an ArrayList instead of a Vector and save ourselves the performance penalty on all those synchronized calls.

    So don’t use synchronized collections. If you find yourself having multiple threads hitting the same list then you need to protect the operations on the list, not the individual calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 536k
  • Answers 536k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer EricLaw's page maintains a list of supporting browsers. Current verions… May 17, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Here is one that I just used recently. It was… May 17, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer First of all, you may want to give shorter aliases… May 17, 2026 at 1:19 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Should I use old synchronized Vector collection, ArrayList with synchronized access or Collections.synchronizedList or
When do we use synchronized ArrayList ? We already have Vector which is synchronized.
This question relates to Java collections - specifically Hashtable and Vector - but may
Which of the methods of java Vector class is synchronized.Since there is no explicit
One meme that gets stressed with Java development is always use ArrayList over Vector.
What vector graphic formats can be used to display the in a view in
I have a vector of points, and I need to get those which are
I have a vector array of triangles which basically consist of a bunch of
We have multiple threads calling add(obj) on an ArrayList . My theory is that
I have a program which fetches records from database (using Hibernate) and fills them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.