标签:
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); } } }
标签:
原文地址:http://www.cnblogs.com/Android9527/p/5394792.html