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

  • Home
  • SEARCH
  • 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 8858613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:52:12+00:00 2026-06-14T14:52:12+00:00

I want to make a hash table class in java where I store the

  • 0

I want to make a hash table class in java where I store the key,value pairs in an ArrayList of Linked List’s. I do this by declaring

 ArrayList<LinkedList<T>> storage = new ArrayList();

I then want to create a linkList object that I can use to then create a new linked list inside of each index of the arrayList. I do this by declaring:

  LinkedList<T> list = new LinkedList<T>();

Then I have my add function set up to add elements to the first index of the LinkedList that is inside the Hashed key index of the arrayList as such:

public void add(K key, T value){    
int arrayListIndex = (key.hashCode()) % this.initialCapacity;
    System.out.println(arrayListIndex); //This tells us where we access the Array List;


    if (hashBrown.get(arrayListIndex) == null){

        hashBrown.add(arrayListIndex, list);
        hashBrown.get(arrayListIndex).addFirst(value);
    }
}

Everytime I run this code I receive an error where my index is 7 and my size is 0. This causes an error:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 7, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:571)
    at java.util.ArrayList.get(ArrayList.java:349)
    at FastHashtable.add(FastHashtable.java:72)
    at FastHashtable.main(FastHashtable.java:145)

I am unable to track down where this index out of bounds error is coming from can anyone offer advice. I am fairly new at working with ArrayLists which makes me think my original declaration of the arrayList is incorrect.

  • 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-14T14:52:14+00:00Added an answer on June 14, 2026 at 2:52 pm

    You are confusing an ArrayLists capacity with its size. From the Oracle Java documentation:

    Each ArrayList instance has a capacity. The capacity is the size of the array used to store the elements in the list. It is always at least as large as the list size. As elements are added to an ArrayList, its capacity grows automatically. The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.

    Instead, you should be looking at creating a plain array (e.g. Object[] a = new Object[maxSize]) in which you can actually assign objects (linked lists in this case) at arbitrary index values. If you only want to store linked lists, create a LinkedList<T>[] array.

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

Sidebar

Related Questions

I want to implement a hash table in python. On the table a class
I want to create my custom Hash Table for key with multiple values. For
Say I have a population of key-value pairs which I plan to store in
I am doing a md5 hash, and just want to make sure the result
I have style sheet with a class name changebackgroundcolor i want make change in
I am traversing a HTML document using javascript DOM. I want make a list
I have link for example domain.com/de/controler/action?param=value and I want make actionlink to keep same
I'm writing an array-backed hashtable in Java, where the type of key and value
I want to make a query to use Prolog in java through JPL, I
I want to create a static Hash table to convert strings to integers .

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.