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
Can we have more than one package statement in the source file?
What is the difference between private & public & friendly classes?
What are the two types of exceptions in java? Which are the differences between them?
What are the benefits of operations in java?
What is a short in java?
What loop means?
What does super keyword do?
Define an applet in java?
Which list is sorted in java?
Explain some best practices you would apply while using collection in java?
What is use of valueof () in java?
What are the two ways in which thread can be created?
What is the epoch date?
What one should take care of, while serializing the object?
What is a parameter in simple terms?