ArrayList to Array of Strings in java

前端 未结 5 1681
一向
一向 2021-02-05 11:53
ArrayList newArray = new ArrayList();
newArray = urlList.getUrl();
for( int i = 0 ; i < newArray.size();i++)
{
    System.out.println(newA         


        
5条回答
  •  遥遥无期
    2021-02-05 12:14

    Usually I write

    String[] array = collection.toArray(new String[collection.size()]);
    

    because this way

    1. I get an array of the type that I want.
    2. I don't have to declare the array before calling Collection.toArray(T[]).

提交回复
热议问题