write a progam hashmap & hashtable?

Answers were Sorted based on User's Feedback



write a progam hashmap & hashtable?..

Answer / 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

write a progam hashmap & hashtable?..

Answer / dileep

import java.io.*;
class Hashtable
{
public static void main (String args[])
{
Hashtable h=new hahtable();
h.add("dil");
h.add("ppp");
h.add("kkk");
System.out.println("the value of h is "+h);
System.out.println("the value of size is"+h.size());
}
}
import java.io.*;
class Hashmap
{
public static void main(String args[])
{
h.put("1","kkk");
h.put("2","ppp");
System.out.println("the value of h is"+h);
}
}
suppose if we use the haahtable then the we have to use
Enumeration concept and suppose if we use the HashMap then
we have to use Iterator concept.

Is This Answer Correct ?    3 Yes 4 No

Post New Answer

More Core Java Interview Questions

Give us a program to check for parenthesis matching using stack.

0 Answers   Genpact,


How do you clear a method in java?

0 Answers  


what is difference between type 4 driver and type 1 driver?

2 Answers   CMC, CTS, IBM, JK Technosoft, Napier Healthcare,


if num=687; U have to get num=6+8+7;

4 Answers   CMC,


What is difference between length and length() method in java ?

0 Answers  






what are three ways in which a thread can enter the waiting state? : Java thread

0 Answers  


Is oracle charging for java?

0 Answers  


What is the file extension for java?

0 Answers  


What is the difference amongst jvm spec, jvm implementation, jvm runtime ?

0 Answers  


Name the packages in JDK?

2 Answers  


What is core java used for?

0 Answers  


What is structure of java heap? What is perm gen space in heap?

0 Answers  


Categories