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

What is difference between ++ I and I ++ in java?

0 Answers  


Is java a pure object oriented language?

0 Answers  


What is java volatile?

0 Answers  


What is a databasemetadata?

0 Answers  


Java does not support multiple inheritance. how interface helps in the same?

5 Answers   TCS,






What is “try and catch” in java

2 Answers  


Explain illegalmonitorstateexception and when it will be thrown?

0 Answers  


What are the rules for naming an array?

0 Answers  


What is entry set in java?

0 Answers  


How java is similar to c?

0 Answers  


Can we execute a program without main?

0 Answers  


Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example

0 Answers  


Categories