write a progam hashmap & hashtable?

Answer Posted / ajay yadav

** HASH MAP **
import java.util.*;
class myhashmap
{
public static void main(strings args[])
{
HashMap map=new HashMap();
map.put("fname","abc");
map.put("email","abc@yahoo.com");
map.put("age",21);
map.put("","");
System.out.println(map.get("fname"));
System.out.println(map.get("age"));
}
}

** Hash Table **

import java.util.*;
class testhashtable
{
public static void main(string args[])
{
Hashtable<String,Integer> num=new Hashtable<String.Integer>
();
num.put("one",new Integer(1));
num.put("two",new.Integer(2));
Integer n=(Integer) num.get("two");
if(n!=null)
{
System.out.println("two="+n);
}
}
}


Difference b/w two is...Hash Map allows NULL values whereas
Hash table not.

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When should I use stringbuffer?

776


design an lru cache in java?

740


Differentiate between class and structure.

811


Which package has light weight components in java programming?

882


What is difference between static class and singleton pattern?

681


What is java virtual machine? Explain

771


Explain the significance of class loaders in bootstrap?

710


What do you mean by data type?

778


why are there separate wait and sleep methods? : Java thread

777


Why main function is static?

898


What is an accessor?

1326


what is meant by encapsulation?

837


What do you mean by thread safe?

748


Can we inherit inner class?

735


explain the difference between jdk and jvm?

752