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

标签 java string collections

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

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/

相关文章:

Java 语法到 Groovy 语法

java - Spring Security 3 自定义身份验证要求....需要帮助!

java - 检查列表中的字符串是否可以通过连接同一列表中的元素形成

c++ - 每个C++ STL集合操作的算法效率

java - 在不受 Spring 管理的类中使用 KafkaListener

java - 抑制某些依赖项中 JAR 的 OWASP 结果

arrays - 将 Lua string.match 输出存储到数组

python - '\' 可以在 Python 字符串中吗?

c# - 在 C# 中使用 .Add 的二维数组

Java:声明一叠牌的最佳方式