直接贴上代码
package com.tsinghuait.demo;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import javax.management.StringValueExp;
public class TestHashMap {
/**
* @param args
*/
public static void main(String[] args) {
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("a", "aa");
hashMap.put("b", "bb");
hashMap.put("c", "cc");
Set<Entry<String, String>> set = hashMap.entrySet();
Iterator<Entry<String, String>> iterator = set.iterator();
while(iterator.hasNext()){
Entry<String, String> entry = iterator.next();
String key = entry.getKey();
String value = entry.getValue();
System.out.println("key : " + key + " value :" + value);
}
}
}