gpt4 book ai didi

java - 如何将一组 char[] 添加到 List 中?

转载 作者:行者123 更新时间:2023-12-01 18:52:29 25 4
gpt4 key购买 nike

我有一个List<String>我想添加 char[] 列表.

我无法更改列表的字符串类型。我的目标是将测试字符串中的每个字符作为单个条目添加到列表中。

以下内容无效。我需要改变什么?

    String test = "test";
List<String> list = new ArrayList<String>();

for (char c : test.toCharArray()) {
list.add(c);
}

最佳答案

尝试

separators.add(String.valueOf(c));

分隔符应该是列表对吗?

关于java - 如何将一组 char[] 添加到 List<String> 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15338836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com