Java数组的基础学习教程

Java数组的根底学习教程   type var[]; 或type[] var;   声明数组时不能指定其长度(数组中元素的个数),   Java中使用关键字new创立数组对象,格式为:数组名 = n

Java数组的根底学习教程 type var[]; 或type[] var; 声明数组时不能指定其长度(数组中元素的个数), Java中使用关键字new创立数组对象,格式为:数组名 =new 数组元素的类型 [数组元素的个数] TestNew.: public class TestNew {public static void main(String args[]) {int[] s; int i; s= new int[5] ;for(i =0 ;i <5 ;i++) {s[i] =i ;} for(i =4 ;i >= 0; i--) { System.out.println("" +s[i]) ;} }} 1.动态初始化:数组定义与为数组分配空间和赋值的操作分开 进展; 2.静态初始化:在定义数字的同时就为数组元素分配空间并赋 值; 3.默认初始化:数组是引用类型,它的元素相当于类的成员变 量,因此数组分配空间后,每个元素也被按照成员变量的规那么被 隐士初始化。 TestD.java(动态): public class TestD {public static void main(String args[]) {int a[] ;a =new int[3] ;a[0] =0 ;a[1] =1 ; a[2] =2 ;Date days[] ;days =new Date[3] ;days[0] =new Date(xx,4,5) ;days[1] =new Date(xx,2,31) ;days[2] =new Date(xx,4,4) ;} }class Date {int year,month,day ; Date(int year ,int month ,int day) {this.year =year ; this.month =month ;this.day =day ;} }

腾讯文库Java数组的基础学习教程