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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:49:46+00:00 2026-06-14T02:49:46+00:00

I understand the idea behind a hash table, but the implementation is getting frustrating.

  • 0

I understand the idea behind a hash table, but the implementation is getting frustrating. I have done some reading and gotten mixed answers. I have read that I could implement a generic array of objects as follows:

TableContainer[] classTable = 
    (TableContainer<Object,Object>[]) new TableContainer[256];

where tableContainer is:

class TableContainer<key,val>{
    Object key = null;
    Object val = null;
}

The problem I am having is that when I try to pass the following code in a function:

classTable[i].key = x

I get a null pointer exception. I understand creating generic arrays in java gets messy because of type erasure but I thought the above implementation would work. Is there any way to create a list or array of generics to be utilized as a hashtable? (no hashtable/hashmap classes permitted)

  • 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-14T02:49:48+00:00Added an answer on June 14, 2026 at 2:49 am

    First of all you are creating an empty array:

    new TableContainer[0]
    

    and since you cannot resize arrays over time, it doesn’t have much sense. Providing that you actually create an array of some positive size, you must remember one thing: you created an array of references. And by default each array is initialized to default (zero) values, which happens to be null for references.

    Thus you need something like this:

    classTable = new TableContainer[8];
    classTable[0] = new TableContainer();
    //...later
    if(classTable[0] != null) {  //will pass for [0], but not for [1]
      classTable[0].key
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand the general idea behind the this keyword but I'm having trouble figuring
I understand the idea behind the tree traversal as well as implementations, but here
I am trying to understand the idea behind ArrayAccess Interface, I dont understand what
I understand (I think) the basic idea behind RESTful-ness. Use HTTP methods semantically -
Please not that I fully understand this is a dumb ass idea, but its
I understand this is an easy question but for some reason this just isn't
I understand the idea behind test-driven development, write tests first, code against tests until
I am new to complex data structures. I kind of understand the idea behind
I didn't understand well the idea behind of proxies in ExtJS. Can I use
Check My Understanding of semaphores, please! I understand the idea behind counting semaphores and

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.