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

Which class is the superclass for every class in java programming?

1063


What is re-factoring in software?

1104


What is use of map in java?

1058


How do you start a thread?

1098


What are accessor methods in java?

1057


What is the best way to findout the time/memory consuming process?

1074


What is the difference between preemptive scheduling and time slicing?

1109


Why can't we use static class instead of singleton?

994


Write a java program to check if a number is prime or not?

1081


Is set sorted in java?

992


What does singleton class mean?

1031


A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.

1058


What is a instance variable in java?

1090


What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. Import java.net.* Versus import java.net.socket)?

1168


What is a qms manual?

1041