



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




int[] a; // a is a reference to an array of integers a = new int[20]; // allocates OS storage for 20 integers int[] a = new int[20]; // combines the above into one line a[2] = 173; // gives the array element index 2 the value 173 // array element 2 is the third item in the array a[i] = 34; // array element i – i must be of type byte, // short or int
int[] a = new int[20]; int[] b; // Just a reference variable … b = a; // a[x] and b[x] refer to the same data – there is only one // array. Any change to b[x] will change a[x] identically // and vice versa
int[] a = new int[20]; b = new int[a.length]; for (int i = 0; i < a.length; i++) { b[i] = a[i]; }
int[] a = new int[20]; a[0] = 3; foo(a); void foo(int[] x) { x[1] = 4; }