Understanding Varargs in Java: 2 Minute Guide For Non-Dummies

Understanding Varargs in Java: 2 Minute Guide For Non-Dummies

Note: This article will be emailed to your friend.

Varargs allows variable number of arguments in methods and constructors. Let’s start with a simple example.

public static void main(String … args) {
    for(String arg:args) {
        System.out.println(arg);
    }
}
Varargs can be thought of as an array with simplifications. A simple use case is: int sum(int… data)
Key Points

Method with varargs is called only when no other method signature matches the invocation.
Only [...]

Read the rest of this article (155 words)

Please fill in the following fields

* - Required

Your Name: *

Your E-Mail: *

Your Remarks:

Friend's Name: *

Friend's E-Mail: *

Protected by Comment Guard Pro