ArrayList的<串GT;到的CharSequence [] [英] ArrayList<String> to CharSequence[]

查看:194
本文介绍了ArrayList的<串GT;到的CharSequence []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最容易的方式的CharSequence [] 的ArrayList&LT的;弦乐>

What would be the easiest way to make a CharSequence[] out of ArrayList<String>?

当然,我可以通过每个的ArrayList 项目迭代并复制到的CharSequence 阵列,但也许有更好的/更快方法是什么?

Sure I could iterate through every ArrayList item and copy to CharSequence array, but maybe there is better/faster way?

推荐答案

您可以使用<一个href=\"http://java.sun.com/javase/6/docs/api/java/util/List.html#toArray%28T%5b%5d%29\"><$c$c>List#toArray(T[])这一点。

You can use List#toArray(T[]) for this.

CharSequence[] cs = list.toArray(new CharSequence[list.size()]);

这里有一个小演示:

Here's a little demo:

List<String> list = Arrays.asList("foo", "bar", "waa");
CharSequence[] cs = list.toArray(new CharSequence[list.size()]);
System.out.println(Arrays.toString(cs)); // [foo, bar, waa]

这篇关于ArrayList的&LT;串GT;到的CharSequence []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆