user3551261
user3551261

Reputation: 53

What does '...' mean in java?

I'm a newbie learning about java. And I have a question to ask. Here is a simple code.

double diameter = ...;
double circumference = 3.14 * diameter;

I really don't understand what '...' means. In my opinion, it might be something which is used for abbreviating the code. Am I right?

Upvotes: 0

Views: 122

Answers (2)

Kunamatata
Kunamatata

Reputation: 84

As said this is not a valid java code, however if it was in arguments of a function like this :

public void myMethod(String... strings){
// method body

}

It means that zero or more String objects (or an array of them) may be passed as the parameter(s) for that function.

Have a great day,

Upvotes: 1

merlin2011
merlin2011

Reputation: 75545

As Thomas Jungblut mentioned, this is not valid Java code, and is merely the author letting you know that you can pick any double value.

More generally, if you want to know whether something is valid Java code in a book example, the easiest way is to just write a main method, stick the code in there, and see if it compiles.

Upvotes: 1

Related Questions