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
What does a boolean method return?
If an object is garbage collected, can it become reachable again?
What is integer size in java?
What is a function in programming?
Is map ordered in java?
What is final access modifier in java?
Which sorting is best in java?
What are the two basic ways in which classes that can be run as threads may be defined?
What are runtime exceptions?
What is hasnext in java?
How is a variable stored in memory?
What is bubble sort in java?
What is meant by class and object in java?
How many types of array are there?
What is the final method?