码迷,mamicode.com
首页 > 其他好文 > 详细

Map的遍历

时间:2016-04-15 11:41:28      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

package HashMapTest;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class HashMapTest {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        HashMapTest test = new HashMapTest();
        test.input();
        test.get();
    }
    
    private Map<Integer,String> map;
    private final String[] strArray = {"aaa","bbb","ccc","ddd","eee"};
    
    private void input()
    {
        map = new HashMap<Integer,String>();
        
        for(int i=0;i<5;i++)
        {
            map.put(i, strArray[i]);
        }
    }
    
    private void get()
    {
        Iterator<Entry<Integer, String>> iterator = map.entrySet().iterator();
        while(iterator.hasNext())
        {
            Map.Entry<Integer,String> entry = (Map.Entry<Integer,String>)iterator.next();
            int key = entry.getKey();
            String value = entry.getValue();
            
            System.out.println("key="+key+",value="+value);
        }
    }
}

 

Map的遍历

标签:

原文地址:http://www.cnblogs.com/Android9527/p/5394792.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!