3 dot in parameter in Java

0 votes

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,380 points
576 views

1 answer to this question.

0 votes

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("xyz"); 
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,320 points

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,040 points
27 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
246 views
0 votes
1 answer

How can I convert a String variable to a primitive int in Java

You can convert a String to int by using a function: int ...READ MORE

answered Apr 12, 2018 in Java by sharth
• 3,320 points
107 views
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,450 points
75 views
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
25 views
+5 votes
3 answers

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

You can use Java Runtime.exec() to run python script, ...READ MORE

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

edited Nov 6, 2018 by Omkar 7,030 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,320 points
181 views
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,320 points
303 views