I\'m afraid of varargs. I don\'t know what to use them for.
Plus, it feels dangerous to let people pass as many arguments as they want.
What\'s an example
Varargs is the feature added in java version 1.5.
Why to use this?
How this works?
It creates an array with the given arguments & passes the array to the method.
Example :
public class Solution {
public static void main(String[] args) {
add(5,7);
add(5,7,9);
}
public static void add(int... s){
System.out.println(s.length);
int sum=0;
for(int num:s)
sum=sum+num;
System.out.println("sum is "+sum );
}
}
Output :
2
sum is 12
3
sum is 21