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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:06:08+00:00 2026-05-24T00:06:08+00:00

First and foremost– I have a file of strings. The smallest file is about

  • 0

First and foremost– I have a file of strings. The smallest file is about 20 strings. The largest file is currently 12,000 strings of varying lengths (anywhere from one character to about 80). I suspect I may have up to a 60,000 string file in the future.

Initially I made a standard array of strings with a default size of 200 and doubled the size and copied the array to a new array if needed (while reading the file into the array). This method was pretty fast. However, the readability and extra coding for methods like search or contains was not appealing. I tried a List interface instead– and read the file in using the typical list.add(line) until there were no more lines.

My question is: What is the default size of an ArrayList<> and does this method result in too many allocations/resizes? Is there any performance points I should know about these two methods and which would be better?

  • 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-24T00:06:09+00:00Added an answer on May 24, 2026 at 12:06 am

    ArrayList defaults to size 10. The amortized cost is not very expensive, even if you start with size 1. You could turn the cost down to nearly 0 if you initialize it with a high capacity:

    List myList = new ArrayList<String>(100000);
    

    Also, you should realize that the List interface doesn’t intrinsically have any performance standards. Its implementations like LinkedList and ArrayList do.

    Edit: I’m lazy and would never use a straight array. ArrayList pretty much is the array with all of the functions like add() and remove() built in. The traditional list implementation, the ArrayList, is the alternative that I would usually consider, but if you are going to be searching the thing I’d suggest sorting it once after you’re done loading it, and using an ArrayList to make use of that with binary search.

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

Sidebar

Related Questions

First and foremost, I've been learning JS for about 2-3 hours. I've lost track.
first take a look on this picture from localScope app : i have 2
First and foremost, I have searched this thoroughly and I'm not convinced with any
First and foremost, this is not a question about generating a serial number for
First and foremost please don't scream Use an IDE at me. I have given
First and foremost, I have tried searching and can't really find anything that will
First and foremost, I'm so sorry about how long this question is and appreciate
So far, so good. However, a few issues have arisen. First and foremost, is
First and foremost, thank you all for reading this and helping, I'm very grateful.
First off, I'm coming (back) to Java from C#, so apologies if my terminology

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.