实例37foreach遍历数组

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);
        }
        
    }

}
View Code

 

posted @ 2016-04-18 23:18  超级学渣渣  阅读(156)  评论(0编辑  收藏  举报