CS 101 NOtes 11/11/10 Arrays - a variable that contain multiple data values Arrays are created as follows: int arrName[]; The square brackets indicate this is an array. arrName = new int [100]; The above code allocated memory for 100 integers Most often people declare arrays as follows: int arrName2[] = new int [500]; For our SoundSample arrays, we create the array using the getSamples() method of the Sound class. SoundSample sampArr1[] = s1.getSamples(); where s1 is a Sound object that already exists. You may see arrays in JAVA create as: int[] arrName3; After the memroy is allocated, to access the values in the array, we need to use subscripts. arrName [3] The valid subscript values range from zero to the length of the array minus 1 The array: int arrName4[] = new int[100]; has length of 100 has valid subscribt from 0 to 99 for (int i = 0 ; i < arrName4.length ; i++) arrName4[i] = i * 2; for (int i = 0 ; i < arrName4.length ; i++) arrName4[i] = arrName4[i] * 10; for (int i = 0 ; i < arrName4.length ; i++) System.out.println ("arrName4[" + i + "] : " + arrName4[i]);