From 290e16e80d7194296f74f5f82be3883428b704d0 Mon Sep 17 00:00:00 2001 From: vikash vaibhav Date: Tue, 16 Oct 2018 08:59:00 +0530 Subject: [PATCH] Variable Arguments (Varargs) Method (#19098) if we need a method in which number of parameters varies then use this type. --- .../pages/guide/english/java/methods/index.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/client/src/pages/guide/english/java/methods/index.md b/client/src/pages/guide/english/java/methods/index.md index bd7a15dad7..802b3aec9e 100644 --- a/client/src/pages/guide/english/java/methods/index.md +++ b/client/src/pages/guide/english/java/methods/index.md @@ -48,6 +48,28 @@ public class Car { } } ``` +If we not sure with the distinct number of parameters passed in a method then use 'Variable Arguments (Varargs) Method' + +Initialize parameter with three dots and will have same dataType. +Passed arguments will store in an array and also accessible as array +```java +public class Main +{ + public static void main(String[] args) { + + Main p=new Main(); + + System.out.println(p.sum(5,5,5,5,5,5,5,5,5)); //can pass any number of argument. + } + +int sum(int ...a) //decleration of variable argument method. + {int sum=0; + for(int i=0;i