0

I have implemented android code to get InputStream from webservices and for that I have used AsyncTask. But I cannot understand what is the use of the argument "String... urls" in doInBackground() method. Can anybody explain this? Following is my code for that:

private class DownloadWebpageTask extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
        try {
            return downloadUrl(urls[0]);
        } catch (IOException e) {
            urlText.setText("");
            return "Unable to retrieve web page. URL may be invalid.";
        }
    }
Jay
  • 9,585
  • 6
  • 49
  • 72
Jaimin Modi
  • 1,530
  • 4
  • 20
  • 72

1 Answers1

2

It is nothing but than Variable Argument (Varargs): in java

So you can pass multiple arguments in an array.

Example

public class HelloWorldVarargs {

public static void main(String args[]) {
    test(215, "India", "Delhi");
    test(147, "United States", "New York", "California");
}

public static void test(int some, String... args) {
    System.out.print("\n" + some);
    for(String arg: args) {
        System.out.print(", " + arg);
    }
  }
}
Don Chakkappan
  • 7,397
  • 5
  • 44
  • 59