write a progam hashmap & hashtable?
Answers were Sorted based on User's Feedback
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 |
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 |
what is difference between Exception and Error?
What are the different http methods?
Why we should declare the variables as static and final in interfaces?
How do you reverse sort a list in java?
What is difference between java and java ee?
What happens when main () method is declared as private?
Can we compare two strings in java?
wahts is mean by thread?
22 Answers HCL, TCS,
How do you avoid global variables?
What is the private method modifier?
Explain when we should make an instance variable private.
What is printwriter in java?