北城已荒凉 2011-03-21 05:57 采纳率: 100%
浏览 359
已采纳

将 ArrayList 字符串转换为 String []数组[ duplicate ]

This question already has an answer here:

I'm working in the android environment and have tried the following code, but it doesn't seem to be working.

String [] stockArr = (String[]) stock_list.toArray();

If I define as follows:

String [] stockArr = {"hello", "world"};

it works. Is there something that I'm missing?

</div>

转载于:https://stackoverflow.com/questions/5374311/convert-arrayliststring-to-string-array

  • 写回答

5条回答 默认 最新

  • 零零乙 2011-03-21 06:07
    关注

    Use like this.

    List<String> stockList = new ArrayList<String>();
    stockList.add("stock1");
    stockList.add("stock2");
    
    String[] stockArr = new String[stockList.size()];
    stockArr = stockList.toArray(stockArr);
    
    for(String s : stockArr)
        System.out.println(s);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?