what does the "..." in each function mean? and why in the last function, there is no "..."?
private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
protected Long doInBackground(URL... urls) {
int count = urls.length;
long totalSize = 0;
for (int i = 0; i < count; i++) {
totalSize += Downloader.downloadFile(urls[i]);
publishProgress((int) ((i / (float) count) * 100));
// Escape early if cancel() is called
if (isCancelled()) break;
}
return totalSize;
}
protected void onProgressUpdate(Integer... progress) {
setProgressPercent(progress[0]);
}
protected void onPostExecute(Long result) {
showDialog("Downloaded " + result + " bytes");
}
}
Very short (and basic) answer: That represents a variable number of items "converted" to an array and it should be the last argument. Example:
test("string", false, 20, 75, 31);
void test(String string, boolean bool, int... integers) {
// string = "string"
// bool = false
// integers[0] = 20
// integers[1] = 75
// integers[2] = 31
}
But you can also call
test("text", true, 15);
or
test("wow", true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 100, 123, 345, 9123);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With