Alfred’s Computing Weblog

Alfred Java-cored Computing Weblog

Java | Loop a Map

leave a comment »

I think this is the best way I found to loop through a Map in Java.

public void printMap(Map mp) {
    Iterator it = mp.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pairs = (Map.Entry);
        System.out.println("Key:" + pairs.getKey() + ", Value:" + pairs.getValue());

Reference Source

Written by Alfred

June 29, 2011 at 11:27

Posted in Java

Tagged with , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: