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 is the difference between equals() and == in java?
What does g mean in regex?
Can a set contain duplicates?
Can a abstract class be declared final?
What is byte [] in java?
What is a line break example?
How do you convert int to char in java?
Explain the reason behind ending a program with a system.exit(0)?
What is the difference between overriding and overloading in OOPS.
How do you add an arraylist to an array in java?
java Technical questions asked by JPMC
How do you remove duplicates from an array in java?
Explain the protected field modifier?
If A Class Is Declared Without Any Access Modifiers, Where May The Class Be Accessed?
What is a native method in java programming?