ArrayList<String> newArray = new ArrayList<String>();
newArray = urlList.getUrl();
for( int i = 0 ; i < newArray.size();i++)
{
System.out.println(newArray.get(i));
}
newArray.toArray(mStrings );// is this correct
mStrings = newArray.toArray();// or this to convert ArrayList ot String array here
for( int i = 0 ; i < mStrings.length;i++)
{
System.out.println(mStrings[i]);
}
edit: when i try as below , i get null pointer exception
try
{
newArray.toArray(mStrings );
for( int i = 0 ; i < mStrings.length;i++)
{
System.out.println(mStrings[i]);
}
}catch( NullPointerException e )
{
System.out.println(e);
}
|
|||||||||
|
Depends on what you want to do. Both are correct
Refer here
Refer here In former, you want to get an array. In latter you have an array, you just wanted to fill it up. In your case, first form is preferred as you just want to get an array without bothering size or details. Basically this is what happens in 2nd case:
The only benefit of doing so, is you avoid casting. The two form are the same. If you use Object array. i.e.
Now, If you pass an uninitialized array, you will get a NullPointerException. The best way to do it is:
Please read the document |
|||||||||
|
Usually I write
because this way
|
|||||||||
|
The first option is better as it allows you to pass in a typed array, which is then populated inside the method. The second option returns an Object[] - so you would have to cast it to use String methods. |
|||||||||||||
|
In plain java i'm use something like
for converting list to array. Don't know in android. |
|||
|
How about this
|
|||
|