import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
public class Task {
public static void main(String[] args) {
HashMap<Integer, String> fruit = new HashMap<Integer,String>();
fruit.put(3,"苹果");
fruit.put(4, "香蕉");
Set<Entry<Integer, String>> es = fruit.entrySet();
Iterator<Entry<Integer, String>> it =es.iterator();
while(it.hasNext()){
Entry<Integer,String> entry = it.next();
Integer key = entry.getKey();
String value = entry.getValue();
System.out.println(key+"="+value);
}
}
}
|
|