What are the three dots in Java?

The three dots (...) are used in a function’s declaration as a parameter. These dots allow zero to multiple arguments to be passed when the function is called. The three dots are also known as var args.

svg viewer

Code 1

The following code uses two arguments in a function call.

class main {
public static int function (int ... a) {
int sum = 0;
for (int i : a)
sum += i;
return sum;
}
public static void main( String args[] ) {
int ans = function(1,1);
System.out.println( "Result is "+ ans );
}
}

Code 2

The following code uses three arguments in the same function defined above. This is possible because of the three dots parameter.

class main {
public static int function (int ... a) {
int sum = 0;
for (int i : a)
sum += i;
return sum;
}
public static void main( String args[] ) {
int ans = function(1,1,1);
System.out.println( "Result is "+ ans );
}
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved