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
What is a parameter in matrices?
What is boolean strategy?
What is try-with-resources in java?
what do you mean by stream pipelining in java 8? Explain
What are the data types supported by java? What is autoboxing and unboxing?
Can we overload the main() method?
What is the difference between arraylist and hashset in java?
What is 32 bit float?
What is classname class in java?
What are the types of inner classes (non-static nested class) used in java?
What is the method to declare member of a class static?
From the two, which would be easier to write: synchronization code for ten threads or two threads?
Is there any way to find whether software installed in the
system is registered by just providing the .exe file?
I have tried the following code but its just displaying the
directory structure in the registry.
Here the code :
package com.msi.intaller;
import java.util.Iterator;
import ca.beq.util.win32.registry.RegistryKey;
import ca.beq.util.win32.registry.RootKey;
public class RegistryFinder {
public static void main(String... args) throws Exception
{
RegistryKey.initialize(RegistryFinder.class.getResource("jRe
gistryKey.dll").getFile());
RegistryKey key = new RegistryKey(RootKey.HKLM,
"Software\\ODBC");
for (Iterator
What does it mean that a class or member is final?
Explain the use of shift operator in java. Can you give some examples?