CS1110: Computer Science I Chapter 5 Arrays
One-dimensional Arrays int [] data = new int [4]; data[0] = 1; data[1] = 3; data[2] = 5; data[3] = 7; Arrays are reference type Arrays are created by using new Array size cannot be changed once created
Indexing an Array Element For an array int [] X = new int [length]; We can use X[i] to access an element 0<=i<=length-1
Array Initialization int [] a = new int[2]; Numeric types are initialized to 0, bool types are initialized to false A[0]=10; a[1]=20; int [] a = new int[2] {10, 20}; int [] a = {10, 20}; a.length can be used to determine the number of elements
System.Array.Copy() method public static void Copy(T from[], T to[], int howMany); public static void Copy(T from[], int fromI, T to[], int toI, int howMany);