Beruflich Dokumente
Kultur Dokumente
Chapter 7
Arrays
char[] x;
Z q
int x = 3;
x is a primitive variable.
If we call a method with x as
an argument, we make a
copy of x and the original
copy is not affected by any
changes we make in the
copy.
yMethd( x )
y 3
public int yMethd( int y
)
{
return y++;
}
If I pass x to a method, a copy y is
made and any changes happen to the
copy.
H e l p
H e l p
H e l p
H e l l
H e l l
data
strMethd( out );
char[] out;
...
wholeArray( out )
char[] out;
...
pieceOfArray( out[2] )
public
When wevoid pieceOfArray( char datum )
pass the
{
single element,
datum = ‘W’;
we include the
// won’t change original array
}square brackets.
w
Java I--Copyright © 2000 Tom Hunter
public void start()
{
char[] out = { 'H', 'e', 'l', 'p' };
display.append( "Before out=" + out[0] + out[1] );
wholeArray( out );
pieceOfArray( out[1] );
display.append( "\nAfter out=" + out[0] + out[1]
+ out[2] + out[3] );
}
char demo[][]