November 2005
Intermediate to advanced
304 pages
6h 14m
English
Java programmers often need to write methods that accept a parameter containing multiple values. This might take the form of a List or an array, for example.
public int add(int[] list) {
int sum = 0;
for (int i=0; i < list.length; i++) {
sum += list[i];
}
return sum;
}
The same code could also have been written as several overloaded methods, each with a signature that takes a different number of int parameters. This sometimes makes the method easier to use, since the calling code does not need to create an array first.
public int add(int a, int b) { return a + b; } public int add(int ...Read now
Unlock full access