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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:54:48+00:00 2026-06-10T05:54:48+00:00

I am trying to add a million objects into a list. The time it

  • 0

I am trying to add a million objects into a list. The time it takes to do it, is longer than i have patience to wait for. It also seems to take progressively longer to carry on with each step.

    int size = 1000000;
    Deque<DatastoreElement> content = new LinkedList<DatastoreElement>();

    for (int i = 0; i < size; i++) {

        String k = Utils.getRandomStringOfLength(20);
        String v = Utils.getRandomStringOfLength(300); // goes faster with smaller number

        int metaHash = random.nextInt(10) + 1;
        KVPair kvp = new KVPair(k, v);
        DatastoreElement dse = new DatastoreElement(metaHash, kvp);

        content.addLast(dse); // confirmed problem is here

        if (i % 10000 == 0) {
            System.out.println(i);
        }
    }

I tried adding content to the List, Set with very similar results. It starts up fast and chokes after some number.

What collection should i be using to store a large number of like elements? Am i missing something simple here?

  • 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-10T05:54:49+00:00Added an answer on June 10, 2026 at 5:54 am

    This issue is not with collections in general, and not with the LinkedList as shown (which has O(1) adding characteristics).

    The likely suspect is thus thrashing/swap of memory. Make sure the JVM has enough memory, and the system has more ..

    Switching from LinkedList to ArrayList (or ArrayDeque) will keep O(1) amortized performance, but may have slightly less overhead per-item. (The overhead, and if such a reduction would even matter, depends upon the size of the objects added and the fill ratios of the backing stores.)

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

Sidebar

Related Questions

Trying to add a class object into a List using reflection, but when invoking
I have an ArrayList , which I want to divide into smaller List objects
Trying to add init parameter names to a list in init(ServletConfig) method. public void
Trying to add a 'box' to a form at design time, I looked up
I have been trying add facebook login to my page. I have facebook login
I am using Java+MySql. I am trying to add bulk data (around 40 million
I have been thinking and learning a lot about forms lately trying to add
I'm trying add vertical lines to my grid. I have found some examples but
I have a file with more than a million words, one word in each
I'm trying add data triggers to the default combobox style so each text item

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.