开发者

Convert list into Array

I want to create a String Array with all URLs in 开发者_Go百科the list.

I have a list of URLs stored in a list object myUrlList. Using myUrlList.toString(); returns a String in the form [http://url1, http://url2, http://url3.....].

Also, myUrlList.getSize() returns correctly the number of URLs the list contains.

How can I obtain an array of all the URLs in the list? I tried myUrlList.toArray, (String[]) myUrlList.toArray(), and others with no success. It is not even possible to obtain one element usingmyUrlList.get(position).


You can convert a List (ArrayList, LinkedList, etc.) to an array simply by using the toArray() method, like this:

List<URL> list = new ArrayList<URL>();
URL[] array = list.toArray(new URL[0]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜