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 is a parameter in matrices?

546


What is boolean strategy?

630


What is try-with-resources in java?

618


what do you mean by stream pipelining in java 8? Explain

537


What are the data types supported by java? What is autoboxing and unboxing?

551






Can we overload the main() method?

555


What is the difference between arraylist and hashset in java?

520


What is 32 bit float?

563


What is classname class in java?

538


What are the types of inner classes (non-static nested class) used in java?

572


What is the method to declare member of a class static?

539


From the two, which would be easier to write: synchronization code for ten threads or two threads?

619


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 subkeys = key.subkeys(); subkeys.hasNext();) { RegistryKey subkey = subkeys.next(); System.out.println(subkey.getName()); // You need to check here if there's anything which matches "Mozilla FireFox". } } }

1354


What does it mean that a class or member is final?

559


Explain the use of shift operator in java. Can you give some examples?

545