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 8875575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:00:29+00:00 2026-06-14T19:00:29+00:00

Question1: Does it make sense to specifiy the size of the ArrayList. I know

  • 0

Question1:

Does it make sense to specifiy the size of the ArrayList. I know how many elements is going to carry in my List, is it good to specify the size before hand or it does not even matter.

List<String> list = new ArrayList<String>(1);
list.add("Hello");

List<String> newList = new ArrayList<String>();
newList.add("Hello");

Question2:

The java.util.ConcurrentModificationException occurs when you manipulate (add,remove) a collection while iterating over the same collection. Does that mean there is a thread which is modifying the ArrayList and another Thread iterating the same object.

Question3

Can anyone tell me how i can lock a list?

  • 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-06-14T19:00:31+00:00Added an answer on June 14, 2026 at 7:00 pm
    1. It matters if you’re adding a lot of items, as it means the collection won’t need to keep copying its internal buffer as it goes along. With a small list it won’t make much difference. Note that you’re not specifying the size of the ArrayList – you’re specifying its initial capacity:

      List<String> list = new ArrayList<String>(10000);
      System.out.println(list.size()); // 0
      

      You still need to add items to it to change the size – but you can add items up to its capacity before it needs to perform copying internally.

    2. No, there doesn’t have to be an extra thread involved. It just means that you’ve modified the collection while you’re iterating over it. That can very easily be in a single thread:

      for (String item : items) {
          items.add("Foo"); // The next iteration step will fail.
      }
      
    3. You’ll need to give more context. Usually it makes more sense to obtain a lock while you perform some operations on a list.

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

Sidebar

Related Questions

Ok, question does not really make sense. Here is the situation. I have legacy
I have two questions. Does it make sense when I have to choice of
Similar question to, Does it make sense to have multiple tomcat instances on the
Does it make sense to use an OR-mapper? I am putting this question of
2 questions: Does using MVC make it any easier to build 508/WAI compliant sites?
Should be a quick and easy question. Does System.Drawing.Graphics.DrawImage() or Image.Save() by default make
I'm using Boost Graph to try and make sense of some dependency graphs I
Hopefully this will make sense. I have a page where an user can create
Question:- Does java client need to worry about multiple servers ? Meaning:- I have
[Question] Does anyone product release notes via an automated process? If so how. Especially

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.