Java multiple arguments dot notation - Varargs

JavaConstants

Java Problem Overview


I've just acknowledged dot notation for method declaration with multiple arguments
like this:

public function getURLs(URL... urls){
    for(int i = 0; i < urls.length; i++){
        // walk through array of arguments
    }
}

And using like this

getURLs(url1, url2, url3);

where those method arguments are converted implicitly into URL[] urls

  1. Did I understand its behavior properly?
  2. Where is documentation to this syntax?
  3. From which version of JRE (J2ME,J2SE,Dalvik) is this supported?

Java Solutions


Solution 1 - Java

Yes, that is how it works. The arguments are automatically put into an array. The argument "urls" behaves like a URL[]. Varargs are documented here. They were introduced in Java 1.5, so, are available in J2SE 1.5+, and all of Android since it supports Java 1.5+ language features. No version of JavaME/J2ME supports it.

Solution 2 - Java

The syntax was introduced in Java 5 and is called varargs:

http://download.oracle.com/javase/1,5.0/docs/guide/language/varargs.html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMarek SeberaView Question on Stackoverflow
Solution 1 - JavaSean OwenView Answer on Stackoverflow
Solution 2 - JavaRuss HaywardView Answer on Stackoverflow