本帖最后由 CoeusLYJ 于 2015-5-7 14:09 编辑
- package cn.itcast.map.demo;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Set;
- public class LinkedHashMap {
- public static void main(String[] args){
- HashMap<Integer,String> m1=new LinkedHashMa<Integer,String>(); //在我的eclipse中,LinkedHashMap这里是有红色波浪线的
- m1.put(58, "zhangsan");
- m1.put(32, "susan");
- m1.put(9, "madrid");
- m1.put(21, "greece");
- Set<Map.Entry<Integer, String>> s1=m1.entrySet();
- Iterator<Map.Entry<Integer,String>> it=s1.iterator();
- while(it.hasNext()){
- Map.Entry<Integer, String> en=it.next();
- Integer Key=en.getKey();
- String Value=en.getValue();
- System.out.println(Key+":"+Value);
- }
- }
- }
复制代码 |
|