The java.lang.reflect.Method.isVarArgs() method of Method class checks whether Method Object was declared to take a variable number of arguments or not. If the method can take a variable number of arguments then returns true otherwise it will return false.
VarArgs allows method to accept a number of arguments. It is a better approach to pass arguments than array when it is not known how many arguments to pass in method.
public boolean isVarArgs()
Return Value: This method returns true if and only if Method has variable-length arguments else false.
Below programs illustrates isVarArgs() method of Method class:
Example 1: Below program checks GFG class methods whether Method has variable-length arguments or not. In this program a method accepts VarArgs and by isVarArgs() check method accept VarArgs or not and at last print the result.
public static void GFG.paint(java.lang.Object) method accepts VarArgs :true
Example 2: This program is going to return all the Methods which contains variable-length arguments of class java.util.Collections.
Explanation: In this Method at first java.util.Collections Class Object is created. After creating Class Object of java.util.Collections Class a list of Method Objects is created by calling getMethods() of class Object. Iterate through Method list and get Method contains variable-length arguments using isVarArgs(). At last print Synthetic Method name.
Methods of Collections Class contains VarArgs Method: addAll
- Constructor isVarArgs() method in Java with Examples
- Method Class | getTypeParameters() Method in Java
- Method Class | getName() Method in Java
- Method Class | getAnnotatedReturnType() method in Java
- Method Class | getParameterAnnotations() method in Java
- Method Class | isBridge() Method in Java
- Method Class | toGenericString() method in Java
- Method Class | getGenericParameterTypes() method in Java
- Method Class | equals() Method in Java
- Method class isSynthetic() method in Java
- Method Class | getReturnType() Method in Java
- Method Class | getExceptionTypes() Method in Java
- Method Class | hashCode() Method in Java
- Method Class | getParameterTypes() Method in Java
- Method Class | getParameterCount() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.