How to Add elements to hash map and Display?

package javaprgms;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class Mapiterator {

            @SuppressWarnings({ "unchecked", "rawtypes" })
            public static void main(String[] args) {

                        HashMap map=new HashMap();

                        map.put(1, "indhu");
                        map.put("d", "sindhu");
                        map.put("3", "swathi");

                        if(!map.isEmpty()){

                                    Iterator it=map.entrySet().iterator();

                                    while(it.hasNext()){

                                                Map.Entry obj=(Entry) it.next();
                                                System.out.println(obj.getValue());

                                    }

                        }

            }

}

indhu
swathi

Sindhu

No comments:

Post a Comment