Hashtable implements Map

Hashtable implements Map:-
 
Hashtable based implementation of the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

import java.util.Hashtable;

import java.util.Iterator;

import java.util.Set;

import java.util.Map;



public class HashTableJava {



    public static void main(String[] args) {



        Hashtable<Integer,String> hTable=new Hashtable<Integer,String>();



        hTable.put(new Integer(2), "Two");

        hTable.put(new Integer(1), "One");

        hTable.put(new Integer(4), "Four");

        hTable.put(new Integer(3), "Three");

        hTable.put(new Integer(5), "Five");



        Set s =hTable.entrySet();



        Iterator i=s.iterator();



        while(i.hasNext())

        {

            Map.Entry m=(Map.Entry)i.next();



            int key = (Integer)m.getKey();

            String value=(String)m.getValue();



            System.out.println("Key :"+key+"  value :"+value);

        }

    }

}

Output

Key :5 value :Five
Key :4 value :Four
Key :3 value :Three
Key :2 value :Two
Key :1 value :One


People who read this post also read :



0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More