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); } } } |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |