public class Welcome{
public static void main(String[] args){
String[] greeting=new String[3];
greeting[0]="Welcome to Core java";
greeting[1]="by Cay Horstmann";
greeting[2]="and Gary Cornell";
for(int i=0; i<greeting.length; i++){
System.out.println(greeting[i]);
}
}
}
声明:int[] a;
初始化:a = new int[100];
得到数组的元素数目,可以使用arrayName.length
Java中有个创建数组对象并同时赋值的简写形式:int[] small={2,3,4};
拷贝数组:可以把一个数组拷贝给另一个,这时两个变量都指向相同的数组。
如果实际只是想一个数组的值拷贝给另一个变量,那么需要使用Stystem类中的arraycopy方法:System.arraycopy(from, fromIndex, to, toIndex, count);