3 dot in parameter in Java

+1 vote

Can someone explain the meaning of the 3 dots, that we always use in our main method in Java?

public static void main(String... args[]){
    // method body
Nov 21, 2018 in Java by misc.edu04
• 1,430 points

1 answer to this question.

+1 vote
Best answer

The "Three Dots" in java is called the Variable Arguments or varargs. It allows the method to accept zero or multiple arguments. Varargs are very helpful if you don't know how many arguments you will have to pass in the method.

For Example:

abc(); // Likely useless, but possible 
abc("x", "y", "z"); 
abc(new String[]{"x", "y", "z"});

But one thing you must not is, the argument that gets the ... must be the last in the method signature. In simpler terms, 

abc (int i, String... strings) is correct, whereas:

abc(String... strings, int i) is wrong.

answered Nov 21, 2018 by geek.erkami
• 2,660 points

selected Oct 23, 2019 by Kalgi
Simple and superb answer. Thanks

Related Questions In Java

0 votes
2 answers

How can we pass a function as a parameter in java?

Java 8 and above Using Java 8+ lambda ...READ MORE

answered Aug 28, 2018 in Java by Daisy
• 8,080 points
+2 votes
0 answers
+1 vote
3 answers



answered Jul 25, 2018 in Java by samarth295
• 2,190 points
0 votes
2 answers



answered Aug 20, 2019 in Java by Sirajul
• 45,310 points
0 votes
1 answer

Purpose of “String args[]” in the “psvm” of Java

Let me give you the complete explanation ...READ MORE

answered May 7, 2018 in Java by code.reaper12
• 3,470 points
0 votes
1 answer
0 votes
1 answer

Running Java program without main method.

This would have worked fine till Java ...READ MORE

answered Nov 21, 2018 in Java by Anoop
+5 votes
3 answers

How to execute a python file with few arguments in java?


answered Mar 27, 2018 in Java by DragonLord999
• 8,400 points

edited Nov 6, 2018 by Omkar 12,847 views
0 votes
1 answer

Sorting an ArrayList in Java

You can easily do this by simply ...READ MORE

answered May 4, 2018 in Java by geek.erkami
• 2,660 points
0 votes
1 answer

Why the main() method in Java is always static?

As you might know, static here is ...READ MORE

answered May 8, 2018 in Java by geek.erkami
• 2,660 points