Monday, July 18, 2011

JAVA CODE TO ITERATE MAP

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

/**
*
* @author RK
*/
public class MapTest {

public static void main(String RK[]) {
Map mapObj = new HashMap();
mapObj.put(1, "ONE");
mapObj.put(2, "TWO");
Iterator it = mapObj.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry) it.next();
System.out.println(pairs.getKey() + " = " + pairs.getValue());

}
}
}


Friend , leave your commnets. Your comments are heartly invited

No comments:

Post a Comment