When defining an ASyncTask and it associated methods in Android there are 3 dots that appear, eg protected Long doInBackground(URL... urls)
What do the dots mean?
When defining an ASyncTask and it associated methods in Android there are 3 dots that appear, eg protected Long doInBackground(URL... urls)
What do the dots mean?
It's not entirely the same thing. Consider the following examples
Example 1:
public String concatenateStrings(String... strings){
StringBuffer sb = new StringBuffer();
for( int i = 0; i < strings.length; i++ )
sb.append( strings[i] );
return sb.toString();
}
Example 2:
public String concatenateStrings2(String[] strings){
StringBuffer sb = new StringBuffer();
for( int i = 0; i < strings.length; i++ )
sb.append( strings[i] );
return sb.toString();
}
They're allmost identical, right? Wrong, calling them is the big difference. The first example allows for an undefined number of strings to be added.
Example 1:
concantenateStrings("hello", "World", " I ", " can ", " add ", " so ", " many strings here" );
Example 2:
Strings[] myStrings = new Strings[7];
myStrings[0] = "Hello";
myStrings[1] = "world";
myStrings[2] = " I ";
...
myStrings[6] = " many strings here";
concatenateStrings2( myStrings );
This is not AsynTask specific or Android specific for that matter. It's a Java feature to pass variable length of parameters to a method.
Have a look at: How to create Java method that accepts variable number of arguments?
It java concept. It looks like array. (and you process it mostly like you process on array). But, it 's different in some points.
You will meet this commonly in android, for example when you use view animation
or property animation
for layout.