重新认识Java(5)——————增强for循环

JDK5.0 新特性 :

foreache语句:

        格式:

                  for(数据类型 变量名 : 被遍历的对象){

                     //被遍历的对象数组或集合

                  }

作用:只能用来遍历

eg:使用方法

int[] arr = new int[]{1,2,3,4,5};  
		//foreach语句实现,遍历操作
		//只能用来遍历
		for(int num : arr){
			System.out.println(num);
		}

猜你喜欢

转载自blog.csdn.net/m0_37729047/article/details/81287872