Methods which uses variable arguments (varargs, arguments with three dots) are known as variadic functions.

Example

What are variadic functions in Java?



Methods which uses variable arguments (varargs, arguments with three dots) are known as variadic functions.

Example

Live Demo

public class Sample {
    void demoMethod(String... args) {
      for (String arg: args) {
         System.out.println(arg);
      }
    }

   public static void main(String args[] ){
      new Sample().demoMethod("ram", "rahim", "robert");
      new Sample().demoMethod("krishna", "kasyap");
   }
}

Output

ram
rahim
robert
krishna
kasyap
Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements