Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

They had given one progam
final HashMap hm=new HashMap();
public void show()
{
hm.put("name",value);
}
in this prg here the final hashtable value can be changed in
put method,its the prg run?

Answer Posted / abhinav mutreja

Thats Correct that contents of the HashMap can be changed
even if HashMap is declared as final.
If you contents also should not get changed then you can use

Map hm = Collections.unmodifiableMap(new HashMap());
here if you do
hm.put(1,"Hi");

then it would give Runtime Exception :-
Exception in thread "main"
java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableMap.put
(Unknown Source)

Is This Answer Correct ?    8 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the java reflection api? Why it’s so important to have?

924


define polymorphism in java

1039


Can we override constructors in java?

1072


How do you sort arrays in java?

878


Do we have pointers in java?

898


What is the purpose of interface?

948


Which way a developer should use for creating thread, i.e. Sub classing thread or implementing runnable.

883


What is the full meaning of java?

993


How can an exception be thrown manually by a programmer?

927


Why declare Main() inside the class in java ?

991


How do you compare arrays in java?

882


What are features of java?

977


What is a methodologist?

993


When does an object becomes eligible for garbage collection in java?

1005


What is the purpose of lambda expressions?

997