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?
Answers were Sorted based on User's Feedback
Answer / kr
hash map values can be modified but the hashmap object
cannot be modified
hm.put("name",value); //allowed
hm = new HashMap() // throw error since the object is fianl
| Is This Answer Correct ? | 19 Yes | 1 No |
Answer / 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 |
What is the inheritance?
What is the difference between break and continue statements?
Which method returns the length of a string?
What the difference is between execute, execute Query, execute Update?
Difference between a process and a program?
What is a layout manager and what are different types of layout managers available in java awt?
What is the use of static class?
How to reverse string in java?
How will you load a specific locale?
What is a ?
JVM is platform independent or depeneded?
Can we override compareto method?