标签:
package cn.stat.p9.map.demo; import java.util.ArrayList; public class Listfor { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ArrayList<String> al=new ArrayList<String>(); al.add("asdf"); al.add("qwer"); al.add("zxcv"); al.add("yuio"); for(String s : al) { System.out.println(s); } } }
foreach语句格式
for(类型 变量 :Collection集合或数组
{
}
//foreach 遍历map集合,要先转成单列的set Map<Integer,String> al=new TreeMap<Integer,String>(); al.put(12,"asdf"); al.put(32,"qwer"); al.put(65,"zxcv"); al.put(10,"yuio"); for(Integer key : al.keySet()) { String value=al.get(key); System.out.println("key="+value); } for(Map.Entry<Integer, String> me : al.entrySet()) { Integer key =me.getKey(); String value=me.getValue(); System.out.println(key+" "+value); }
标签:
原文地址:http://www.cnblogs.com/zywf/p/4758478.html