Hackforge Academy

Category: React • Beginner

Published on 22 Feb 2026

Explanation

#white-Varargs allow a method to accept a #white-variable number of arguments.

Code Example

void display(int... numbers) {
    for(int n : numbers) {
        System.out.println(n);
    }
}

Explanation

#white-Varargs are treated as arrays inside the method.

Code Example

void sum(int... values) {
    System.out.println(values.length);
}

Explanation

#white-Varargs parameter must be the last #white-parameter in the method.

Code Example

void example(String name, int... marks) { }

Explanation

#white-You can call varargs method with zero or #white-more arguments.

Code Example

display();
display(1, 2, 3);

Explanation

#white-Only one varargs parameter is allowed in a #white-method.

Code Example

// void test(int... a, int... b) {} // Not allowed

Want structured learning with real projects?

Join our Weekend Live Workshop and become job-ready faster.