将字符串转换为数组列表 <Character>在 Java 中 [英] convert string to arraylist <Character> in java

查看:34
本文介绍了将字符串转换为数组列表 <Character>在 Java 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将没有分隔符的字符串转换为ArrayList.

How to convert a String without separator to an ArrayList<Character>.

我的字符串是这样的:

String str = "abcd..."

我知道一种方法是先将 String 转换为 char[],然后将 char [] 转换为 ArrayList ;.

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);
}

这篇关于将字符串转换为数组列表 &lt;Character&gt;在 Java 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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