ArrayList<String>到字符序列[] [英] ArrayList<String> to CharSequence[]
本文介绍了ArrayList<String>到字符序列[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从 ArrayList
生成 CharSequence[]
的最简单方法是什么?
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?
推荐答案
您可以使用 List#toArray(T[])
为此.
You can use List#toArray(T[])
for this.
CharSequence[] cs = list.toArray(new CharSequence[list.size()]);
这是一个小演示:
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<String>到字符序列[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文