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
Is arraylist dynamic in java?
Can an arraylist be empty?
Can we sort a map in java?
Explain inheritance in java?
What is the parse method in java?
How do singleton patterns work?
What is the difference between exception and error in java?
Can we assign null to double in java?
Difference between a process and a program?
Why is it important to initialize a variable?
What is number data type in java?
What is the abstraction?
What is empty list in java?
How are destructors defined in java?
How do you override a method?