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 are the two types of java?

1177


Explain how can you debug the Java code?

1077


How do you replace a string in java?

1011


What does i ++ mean in Java?

958


Is call by reference possible in java?

967


Explain when classnotfoundexception will be raised ?

1043


Can we convert integer to string in java?

1056


What is equals method in java?

1041


How to sort array in descending order in java?

924


What is java english?

1008


What is the difference between synchronized and synchronized block?

1068


Can list be null in java?

1042


Give a practical example of singleton class usage?

1059


What is the difference between int and integer in java?

1034


Can interface be private in java?

1031