Varags in Java
Sometimes you might need to write methods that accept an argument that contains multiple values. In such case an array could be the type to use.
Instead of using an array, another option could have been to create several overloaded methods that would take different number of arguments. From Java 5, we can write a method so that it allows a variable number of parameters and let the compiler do the work of packaging the list into an array.
An array is still used internally, but the details are hidden by the compiler.
Instead of using an array, another option could have been to create several overloaded methods that would take different number of arguments. From Java 5, we can write a method so that it allows a variable number of parameters and let the compiler do the work of packaging the list into an array.
An array is still used internally, but the details are hidden by the compiler.