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

What is quick sort in java?

796


What is a newline character in java?

797


Can a static class have a constructor java?

746


What is garbage collector?

829


What are the differences between throw and throws?

851


os is developed in c no java is more secured then c na why dont the os developed is developed using java

3856


How do you download stubs from Remote place?

1549


How do we access static members in java?

853


What is the major advantage of external iteration over internal iteration?

840


When we should use serialization?

804


What is nan inf?

703


In java, what is the difference between method overloading and method overriding?

827


What do you mean by default constructor in java?

824


Is vector synchronized in java?

739


Can we override final method?

765