Java Reference
In-Depth Information
We get the following output:
type:[[I@addbf1 5
type:[I@42e816 1
type:[I@9304b1 2
type:[I@190d11 3
type:[I@a90653 4
type:[I@de6ced 5
Observe that array
ragged
is printed as a bi-dimensional array of integers
using the “[[” notational convention:
[[I@addbf1
. Similarly to Figure 4.1, we
can visualize ragged arrays as depicted in Figure 4.2.
4.6 Arrays of strings and
main
function
Strings of type
String
are
not
primitive types of Java. Though they can
be constructed from literals and are immutable, strings are considered as
special Java objects. Strings are
not
arrays of characters
char
. In other words,
String
=
char []
.
These object notions shall be explained in the next chapter. We can also build
arrays of strings that are of type
String []
, and functions may have string
arrays as arguments. Actually, we are already very familiar with the
main
function of all Java programs that take as argument an array of strings:
class ProgramName
{
public static void main(String[ ] args)
{
...
}
}
For example, the following program lists all string arguments given in the line
command when invoking the java virtual machine on the bytecode:
Program 4.13
Writing to the output the arguments of the invoked
main
function
class
ParsingMain
{
public static void
main( String [ ]
args )
for
(
int
i=0;i
<
args . length ; i++)
System . out . println ( i+
":"
+args [ i ] ) ;
}
}
Search WWH ::
Custom Search