Feature | Syntax | Example |
---|---|---|
Declaration | data-type [] variable-name; | int [] gradeArray; Card [] deck; |
Declaration (alternative) |
data-type variable-name[]; | int gradeArray []; Card deck []; |
Initializer list | data-type [] list = { value, value, ... value} | String [] names = { "bob", "ann", "amy", "sue", "sam"}; |
Instantiation | new data-type[int-value] | intArray = new int [25]; deck = new Card [cardCount]; |
Instantiation and initialization | new data-type[] { value, value, ... value } | names
= new String [] { "bob",
"ann", "sue", "sam" }; return new int [] {0}; |
Referring to the array as a whole |
var-name | return deck; intArray = grades; array2.equals(array1); arrLength = names.length; |
Specialized Arrays methods | java.util.Arrays.fill(grades, 100); java.util.Arrays.equals(section1, section2); java.util.Arrays.sort(names); java.util.Arrays.toString(names) |
|
Referring to array elements | var-name[int-value] | return deck[0]; intArray[ii] = grades[jj]; rank = deck[ii].getRank(); while (intArray[ii] == 5) |