write a progam hashmap & hashtable?

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


Please Help Members By Posting Answers For Below Questions

what are Hostile Applets?

1608


What is the purpose of extern variable?

541


What is tochararray in java?

504


Who found java?

553


What comes to mind when someone mentions a shallow copy in java?

662






Is it correct to say that due to garbage collection feature in java, a java program never goes out of memory?

580


Why main method is static in java?

598


What is rmi and steps involved in developing an rmi object?

571


What is the use of System class?

614


What is java util list?

489


Can the garbage collection be forced by any means?

534


What is meant by memory leak?

543


What is n in java?

539


State the difference between strings and arrays.

603


How many types of parsers are there?

554