E81 CSE 131 Lecture 3: Arrays Syntax and Usage
magentarat813 and 20 others unlocked
8
E81 CSE 131 Full Course Notes
Verified Note
8 documents
Document Summary
String[] names = { bob, carol, alice }; The type of each element contained in the array is followed by an opening and closing bracket. Either list the array elements in braces or use new provision for elements you will assign later. 131 is the number of elements we want to put inside of the array. Referencing elements of an array names[ i ] References the ith element of the names array. In place of i, any integer-valued expression can be used. The elements of the array start with index 0. And therefore stop just 1 short of the length of the array. String[] names = { alice, bob, carol }; names[0] has alice names[1] has bob names[2] has carol names. length is 3. String[] names = {alice, bob, carol}; names[2] = names[0]; carol now has the value of alice names[0] = names[1];