Here we write a program which is a simple Hash Map example.
package com.javaforecast4u;
import java.util.*;
public class TestHashMap {
/**
* @author:arbind;
*/
public static void main(String[] args) {
HashMap
hm=new HashMap();
hm.put("empid","1000");
hm.put("empname","arbind");
hm.put("email","arbind@gmail.com");
hm.put("phone",new Integer(1000000));
System.out.println(hm);
System.out.println(hm.containsKey("sname"));
System.out.println(hm.containsKey("xyz"));
System.out.println(hm.containsValue("9999999"));
System.out.println(hm.containsValue("muktesh"));
System.out.println(hm.size());
System.out.println(hm.isEmpty());
Collection
c=hm.values();
Iterator
i=c.iterator();
while(i.hasNext())
{
System.out.println(i.next());
}
System.out.println("........................");
System.out.println(hm.get("phone"));
Set
s=hm.keySet();
Iterator
i1=s.iterator();
while(i1.hasNext())
{
String
key=i1.next().toString();
String
val=hm.get(key).toString();
System.out.println(""+key+"\t---\t"+val);
System.out.println(i1.next());
}
}
}
0 comments :
Post a Comment