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
Which sorting algorithm is best in java?
Print Vertical traversal of a Binary Tree.
What causes memory leak in java?
What is "this" keyword in java? Explain
What does flag mean in java?
What is int argc char * argv?
What is an infinite loop? How infinite loop is declared?
What is a java list?
What is double word?
How java uses the string and stringbuffer classes?
How is garbage collection controlled?
What is an object class?
What is thread safe java?
What is this keyword in java?
What is difference between c++ and java ?