实例37foreach遍历数组
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package test; import java.util.List; import java.util.ArrayList; import java.util.Scanner; /** * @author 年浩 * */ public class test { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); List<String>list = new ArrayList<String>(); list.add("abc"); list.add("def"); list.add("ghi"); list.add("jkl"); list.add("mno"); list.add("pqr"); System.out.println("用foreach循环遍历list:"); for(String string:list){//遍历list集合 System.out.println(string); } System.out.println(); String[] strs = new String [list.size()]; list.toArray(strs); System.out.println("用foreach遍历数组"); for(String str:strs){ System.out.println(str); } } }