Java基础知识02-增强型的foreach循环

来源:互联网 发布:python float to int 编辑:程序博客网 时间:2024/06/06 11:44

package cn.aparke.bbs.day04;

public class TestArgsArray {    public static void main(String[] args) {        //System.out.println(null!=args);        System.out.println("数组args的长度为:"+args.length);        if (args.length !=0 ) {            //普通for循环            /*for (int i = 0; i < args.length; i++) {                System.out.println("hello:"+args[i]);            }*/            /*             * 在JDK5.0中除了之前的三种普通循环(while、             * do-while、普通for)             * 结构外,提供了一个增强型的foreach循环             *              * 语法:             *   for (数据类型 变量(或对象)名 : 数组或者集合) {                    //可以直接操作变量或者对象                  }                   没有下标(索引)这些概念了,直接操作数组中的数据了             *              */            for (String str : args) {                System.out.println("hello:"+str);            }        }else{            System.out.println("对不起,args数组中没有任何数据");        }    }}
原创粉丝点击