A4
A4
Example:
19-3
19-4 Arrays.fill(pk, 77); //Array now looks like this {77, 77, 77, 77, 77}
String equivalent:
An entire array can be converted to a String similar to “[2, -3, 5, 18, 22]”. Example:
Arrays.toString(myArray); //Typically printed as a test
The above discussion is for the int type arrays; however, all methods work for arrays of any
of the primitive types and Strings. The sort method works for objects from any class
implementing the Comparable interface... All methods are static.
Let’s take a final look at the signature for the main method: public static void main(String
args[])
Now that we know about arrays, we can see that “String args[ ]” is declaring args as a String
array. But where and how is this args[ ] array to be used? (Incidentally, this args[ ] array
could be called by any legal variable name.)
The args[ ] array allows us to pass command line arguments to the main method. Entering a
command line (see Appendix X) at the DOS prompt is one way to run a Java program. To do
this you would need to be in a DOS console via the sequence Start | Run | cmd (don’t use the
older command) | OK):
What exactly does all this mean? The leading word java means to run the Java executable file
(java.exe), MyClass (shown below) is the class containing the main method you wish to run,
-46 is a String representing the first parameter we are passing ( stored in args[0] ), and
Fleetwood.bat is a String representing the second parameter we are passing ( stored in args[1]
).