Variable Argument method | JAVA

snehal_wagh
Mar 28, 2021

--

This Article will give you insights on how to create a variable argument method in java.

Variable argument method is mainly used when

  1. we are not aware of the number of arguments that are going to be passed at runtime.
  2. one method will perform same operations for 0 or more than 0 no. of arguments.

Variable arguments are declared as datatype followed by 3 dots : String…

Consider the following example:

Here the method varIntArgMethod() is a variable argument method which will accept integer arguments and perform summation on those variables.

Output for the above code :

--

--

snehal_wagh
snehal_wagh

No responses yet