将字符串转换为arraylist< Character>在java中 [英] convert string to arraylist <Character> in java
本文介绍了将字符串转换为arraylist< Character>在java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将不带分隔符的String转换为 ArrayList< Character>
。
How to convert a String without separator to an ArrayList<Character>
.
我的字符串是这样的:
String str = "abcd..."
我知道一种方法是首先将String转换为 char []
,然后转换 char []
to ArrayList< Character>
。
I know one way of doing this is converting the String to char[]
first, and then convert the char []
to ArrayList <Character>
.
是否有有没有更好的方法呢?喜欢直接转换?考虑时间和性能,因为我正在使用大型数据库进行编码。
Is there any better way to do this? like converting directly? Considering time and performance, because I am coding with a big database.
推荐答案
您需要像这样添加它。
String str = "abcd...";
ArrayList<Character> chars = new ArrayList<Character>();
for (char c : str.toCharArray()) {
chars.add(c);
}
这篇关于将字符串转换为arraylist< Character>在java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文