Java 数组初始化的两种方法

  1. 静态初始化:程序员在初始化数组时为数组每个元素赋值;
  2. 动态初始化:数组初始化时,程序员只指定数组的长度,由系统为每个元素赋初值。
public class ArrayInit {  
    public static void main(String[] args) {     
        //静态初始化数组:方法一  
        String cats[] = new String[] {  
                "A","B","C"  
        };     
        //静态初始化数组:方法二  
        String dogs[] = {"D","E","F"};   
        //动态初始化数据  
        String books[] = new String[2];  
        books[0] = "SSM";  
        books[1] = "SSH";  
    }  
} 

你可能感兴趣的:(JavaSE)