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
232 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,020 points
18 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
99 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,310 points
45 views
0 votes
5 answers

How to compare Strings in Java?

String fooString1 = new String("foo"); String fooString2 = ...READ MORE

answered Jul 12, 2018 in Java by Daisy
• 8,020 points
78 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
58 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
21 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,360 points

edited Nov 6, 2018 by Omkar 4,551 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
138 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
197 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.