//在一个循环,同时输出key和value public static void main(String[] args) { Map<String, String> hashMap = new HashMap<String, String>(); hashMap.put("a", "1234"); hashMap.put("m", "oi"); hashMap.put("p", "看"); hashMap.put("d", "fuck"); hashMap.put("e", "2"); hashMap.put("v", "-_-");//以上,添加元素 //将Map接口,变为Set接口 Set<Entry<String, String>> entrySet = hashMap.entrySet(); //得到Iterator Iterator<Entry<String, String>> iterator = entrySet.iterator(); //同时输出key和value while (iterator.hasNext()) { //通过iterator.next(),得到key和value Entry<String, String> next = iterator.next(); System.out.println(next.getKey() + " -> " + next.getValue()); }
Java.在一个循环,同时输出Map的key和value
猜你喜欢
转载自8850702.iteye.com/blog/2282399
今日推荐
周排行