Varargs
Type... collects any number of arguments into an array.
Example
public class Main {
static int sum(int... n) { int t = 0; for (int v : n) t += v; return t; }
public static void main(String[] args) {
System.out.println(sum() + " " + sum(1) + " " + sum(1, 2, 3));
}
}Result
0 1 6
Exercise
Varargs symbol.
int... Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.