Java Reference
In-Depth Information
EXAMPLE (OF ARRAY ARGUMENTS)
char [] c = new char [10];
int [] a = new int [10];
int [] b = new int [20];
Note that arrays a and b have
different lengths. Also note that
no square brackets are used with
array arguments.
<Some code to fill the arrays goes here.>
AClass.listChars(c);
AClass.zeroAll(a);
AClass.zeroAll(b);
Display 6.3
Testing Arrays for Equality (part 1 of 2)
1 public class DifferentEquals
2 {
3 /**
4 A demonstration to see how == and an equalArrays method are different.
5 */
6 public static void main(String[] args)
7 {
8 int [] c = new int [10];
9 int [] d = new int [10];
10 int i;
11 for (i = 0; i < c.length; i++)
12 c[i] = i;
13 for (i = 0; i < d.length; i++)
14 d[i] = i;
15 if (c == d)
16 System.out.println("c and d are equal by ==.");
17 else
18 System.out.println("c and d are not equal by ==.");
The arrays c and d contain
the same integers in each
index position.
19 System.out.println("== only tests memory addresses.");
20 if (equalArrays(c, d))
21 System.out.println(
22 "c and d are equal by the equalArrays method.");
23 else
24 System.out.println(
25 "c and d are not equal by the equalArrays method.");
 
Search WWH ::




Custom Search