java - 如何检测字符串中的空格?

标签 java string

               String  test="This is a simple text"

是否可以通过查看空格来检测空格并写入下一行?我的意思是有这样的控制台输出:

                      This is a simple text
                      ++++ ++ + ++++++ ++++

最佳答案

public class StringPlus {

    public static void main(String[] args) {
        String  test="This is a simple text";
        for(char c: test.toCharArray()){
            System.out.print((c == ' ') ? " ":"+");
        }
    }
}

关于java - 如何检测字符串中的空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20576758/

相关文章:

java - Windows 8 上的 JWrapper EXE 需要 "Run as Administrator..."

python - 字符串创建 : Differences between two syntaxes ' ' and ""?

string - 有没有办法做反Sprintf结果

java - JButton Action 监听器不起作用

java - 在 Class.getDeclaredMethods() 中返回内部 Lambda?

java - 在构造函数中初始化公共(public)静态最终变量

c# - Newtonsoft.Json.Linq.JArray 到字符串数组 C#

python - 如果字符串由单词列表中的单词组成,则匹配没有空格的字符串

Java 字符串标记器

java - 将 jlong​​ 与 unsigned long int 进行转换