We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
It is basically called varargs or variable length arguments in java. The argument is specified with 3 periods(...) after the type. This syntax tells the compiler that the method can be called with 0 or more arguments. One thing to note here is that your method cannot have 2 varargs as arguments and varargs must always be last in method with more than 1 arguments.
For example , void method(int... n1,int... n2) is invalid.
void method(int... n1,int n2) is invalid, but
void method(int n1,int... n2) is valid. It is logical since the compiler knows how many arguments to assign to varargs, thats why it should always be written last in the argument list
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Prime Checker
You are viewing a single comment's thread. Return to all comments →
It is basically called varargs or variable length arguments in java. The argument is specified with 3 periods(...) after the type. This syntax tells the compiler that the method can be called with 0 or more arguments. One thing to note here is that your method cannot have 2 varargs as arguments and varargs must always be last in method with more than 1 arguments. For example , void method(int... n1,int... n2) is invalid. void method(int... n1,int n2) is invalid, but void method(int n1,int... n2) is valid. It is logical since the compiler knows how many arguments to assign to varargs, thats why it should always be written last in the argument list