`
javacto
  • 浏览: 81935 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Enhanced For 【003】

阅读更多
package com.testenhanced;
import java.util.* ;
import java.util.Collection;

public class TestEnhanced {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] arr = {1,2,3,4,5,6} ;
		for(int i: arr) {
			System.out.println(i) ;
		}
		
		Collection c = new ArrayList() ;
		c.add(new String ("asd")) ;
		c.add(new String ("lmn")) ;
		c.add(new String("156")) ;
		for(Object o: c) {
			System.out.println(o) ; 
		}

	}

}

console:
1
2
3
4
5
6
asd
lmn
156


//除了简单遍历并读出其中的内容外,不建议使用增强for
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics