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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:33:08+00:00 2026-05-31T05:33:08+00:00

I have three Hash Table like that, HashTable ht1 = { (1, 100), (2,

  • 0

I have three Hash Table like that,

HashTable ht1 = { (1, 100), (2, 200) }

HashTable ht2 = { (1, 100), (2, 200) }

HashTable value = { (100, null), (200, null) }

Is it possible in Java to store a pointer in ht1 and ht2 instead of 100 and 200, which points (and can access) to 100 and 200 of value hashtable. Example, I want structure like ht1 = { (1, pointer1), (2, pointer2) } where pointer1 —-) 100 (which is stored on value hashtable) Can anybody help me how can this be possible ? I am using Java inbuilt Hashtable construct. Thanks.

  • 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-31T05:33:09+00:00Added an answer on May 31, 2026 at 5:33 am

    A couple of comments. Hashtable is useful when you need to have synchronized access to the elements in a Map, if that’s not the case HashMap is preferred.

    In Java we don’t have “pointers”, but surely we have references to objects (please remember that in Java all objects are passed by value, not by reference). And yes, you can store references to objects as values in a Map. I think you’re confusing concepts from C/C++ with concepts in Java, maybe you should explain exactly what do you want to do with the “pointers”.

    Just to be sure – you can have a Map such as this one in Java:

    Map<Integer, Integer> table = new HashMap<Integer, Integer>();
    

    In the above code, the keys and values of the Map are references to Integer objects, and the Integer class is immutable, meaning that you can’t change its value once it’s in place – but of course, you can change the value pointed to by a key in the Map.

    EDIT :

    The sample in the question would look like this in Java:

    Map<Integer, Integer> ht1 = new HashMap<Integer, Integer>();
    ht1.put(1, 100);
    ht1.put(2, 200);
    
    Map<Integer, Integer> ht2 = new HashMap<Integer, Integer>();
    ht2.put(1, 100);
    ht2.put(2, 200);
    
    Map<Integer, Integer> value = new HashMap<Integer, Integer>();
    value.put(100, null);
    value.put(200, null);
    

    In the above code all the integers in the three maps are references to immutable objects: what appears to be the number 100 in reality is a reference to the object new Integer(100), and because Integer is an immutable class, it’s possible that all three references to new Integer(100) point to exactly the same object in memory.

    So, answering your question: yes it’s possible in Java to store a pointer in ht1 and ht2 instead of 100 and 200, which points (and can access) to 100 and 200 of value hashtable. In fact that’s what is happening already, and there’s no other way to do it – because maps in Java can not store primitive types (like int), only references. And again, given that all instances of Integer are immutable, you can not change their value, because doing so would change the values in the other places where they’re being shared and used.

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

Sidebar

Related Questions

I have a Hash Table like, HashTable ht = { (1, 1), (2, 1),
I have a hash table that I want to store to disk. The list
Are there any built-in C# data structures that are like a hash table but
So if I have to choose between a hash table or a prefix tree
I have three tables: page, attachment, page-attachment I have data like this: page ID
I have three unordered lists that have been created as Scriptaculous Sortables so that
I have three tables in the many-to-many format. I.e, table A, B, and AB
I would like to define a hash table with a swappable hash function. The
I have a hash table where the vast majority of accesses at run-time follow
I would like to write/read a hash-table to/from disk, but it is not a

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.