Varargs (Variable Arguments) in Java


Varargs allow a method to accept zero or multiple arguments.

Source Code

public static void printNumbers(int... numbers) {
    for (int number : numbers) {
        System.out.println(number);
    }
}
public static void main(String[] args) {
    printNumbers(1, 2, 3, 4, 5);
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments