gpt4 book ai didi

java - 将 char 集合转换为不带逗号和方括号的字符串

转载 作者:行者123 更新时间:2023-12-02 04:47:56 25 4
gpt4 key购买 nike

我想打印一个从字符集合转换而来的字符串。但我想从打印字符串中删除逗号(,)和方括号([])。

List<Character> word_to_show = new ArrayList<Character>(); 
for(char ch:jumbled_word.toCharArray()){
word_to_show.add(ch);
}
Collections.shuffle(word_to_show);
for (Object ch: word_to_show)
System.out.print((Character) ch );
System.out.println();
send_to_timer = word_to_show.toString();

我已经到了这个地步。它可以工作,但将字符串打印为,例如 [a, b, c]

最佳答案

您可以使用replace()

string.replace(",","").replace("[","").replace("]","")

Demo

关于java - 将 char 集合转换为不带逗号和方括号的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29509589/

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