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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:18:47+00:00 2026-05-25T22:18:47+00:00

What is the maximum size of HashSet , Vector , LinkedList ? I know

  • 0

What is the maximum size of HashSet, Vector, LinkedList? I know that ArrayList can store more than 3277000 numbers.

However the size of list depends on the memory (heap) size. If it reaches maximum the JDK throws an OutOfMemoryError.

But I don’t know the limit for the number of elements in HashSet, Vector and LinkedList.

  • 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-25T22:18:48+00:00Added an answer on May 25, 2026 at 10:18 pm

    There is no specified maximum size of these structures.

    The actual practical size limit is probably somewhere in the region of Integer.MAX_VALUE (i.e. 2147483647, roughly 2 billion elements), as that’s the maximum size of an array in Java.

    • A HashSet uses a HashMap internally, so it has the same maximum size as that
      • A HashMap uses an array which always has a size that is a power of two, so it can be at most 230 = 1073741824 elements big (since the next power of two is bigger than Integer.MAX_VALUE).
      • Normally the number of elements is at most the number of buckets multiplied by the load factor (0.75 by default). However, when the HashMap stops resizing, then it will still allow you to add elements, exploiting the fact that each bucket is managed via a linked list. Therefore the only limit for elements in a HashMap/HashSet is memory.
    • A Vector uses an array internally which has a maximum size of exactly Integer.MAX_VALUE, so it can’t support more than that many elements
    • A LinkedList doesn’t use an array as the underlying storage, so that doesn’t limit the size. It uses a classical doubly linked list structure with no inherent limit, so its size is only bounded by the available memory. Note that a LinkedList will report the size wrongly if it is bigger than Integer.MAX_VALUE, because it uses a int field to store the size and the return type of size() is int as well.

    Note that while the Collection API does define how a Collection with more than Integer.MAX_VALUE elements should behave. Most importantly it states this the size() documentation:

    If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

    Note that while HashMap, HashSet and LinkedList seem to support more than Integer.MAX_VALUE elements, none of those implement the size() method in this way (i.e. they simply let the internal size field overflow).

    This leads me to believe that other operations also aren’t well-defined in this condition.

    So I’d say it’s safe to use those general-purpose collections with up to Integer.MAX_VLAUE elements. If you know that you’ll need to store more than that, then you should switch to dedicated collection implementations that actually support this.

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

Sidebar

Related Questions

I know maximum size of application in app store is 2GB. and we can
What is maximum size of data that an object can hold on the iPhone?
I wanted to know what is the maximum size of the file that we
In C# 2008, what is the Maximum Size that an Array can hold?
I have a std::vector of values for which I know the maximum size, but
http://site.com/?status=4387hg843hg89473gh87934h89g734hg8973hg9873hg8973h4987g3h489g7h89h849g5 What's the maximum size of status that PHP can read? I want to
What is the maximum size that can be stored in a PHP session?
What's the maximum size of file that can be read in .net Framework ?
Can I change the maximum size from a file that is being upload (using
Possible Duplicate: What is the Maximum Size that an Array can hold? i want

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.