August 2004
Intermediate to advanced
480 pages
9h 41m
English
You can declare a new array variable, just like you would any other member variable (like this)
String[] args;
The square brackets mean “array.” An array in Java is an object, which means that you initialize an array with the keyword new. Like this:
String[] args = new String[10];
This creates a new array object, called args, with 10 buckets for putting Strings into. You can fill an array with whatever kind of thing you want: Object, int, boolean, Address, char, another array, and so on.
The first element of a Java array has an index of 0. To reference the element in the second bucket of an array named args, type this:
args[1]
|
Read now
Unlock full access