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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:14:39+00:00 2026-05-26T14:14:39+00:00

As we know the purpose of final keyword in java. While declaring a variable

  • 0

As we know the purpose of “final” keyword in java. While declaring a variable as final, we have to initialize the variable. like “final int a=10;”
We can not change the value of “a”. But if we go for HashTable its possible to add some value even declaring the HashTable as final.

Example::

 private static final Hashtable<String,Integer> MYHASH = new Hashtable<String,Integer>() 
{{     put("foo",      1);     
       put("bar",      256);     
       put("data",     3);     
       put("moredata", 27);     
       put("hello",    32);     
       put("world",    65536);  }}; 

Now I am declaring the MYHASH HashTable as final. If I try to add some more elements to this, its accepting.

MYHASH.put("NEW DATA",      256);

Now the “NEW DATA” is added to the HashTable.
My questions is Why its allowing to add even its declaring as final????

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

    Because final marks the reference, not the object. You can’t make that reference point to a different hash table. But you can do anything to that object, including adding and removing things.

    Your example of an int is a primitive type, not a reference. Final means you cannot change the value of the variable. So, with an int you cannot change the value of the variable, e.g. make the value of the int different. With an object reference, you cannot change the value of the reference, i.e. which object it points to.

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

Sidebar

Related Questions

I would like to know 1.the purpose of statement closing in java 2.what will
I have been curious to know what is the purpose of having a console
I'd like to know if its conform to the java servlet specification 2.5 to
I know that there are times when using return; can serve a useful purpose
I know that primary keys based on Guids do not have the best performance
I want to know what is purpose of '\' in vb ? I have
I know what Cythons purpose is. It's to write compilable C extensions in a
Does anyone know of a Twitter service proxy in particular, or a general-purpose REST
Ok, I know the difference in purpose. GET is to get some data. Make
I have a django (Python) project that needs to know what version its code

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.