How can I find whitespace in a String?

后端 未结 14 1027
感动是毒
感动是毒 2020-12-01 05:08

How can I check to see if a String contains a whitespace character, an empty space or \" \". If possible, please provide a Java example.

For example: String

相关标签:
14条回答
  • 2020-12-01 05:50
    public static void main(String[] args) {
        System.out.println("test word".contains(" "));
    }
    
    0 讨论(0)
  • 2020-12-01 05:50
    package com.test;
    
    public class Test {
    
        public static void main(String[] args) {
    
            String str = "TestCode ";
            if (str.indexOf(" ") > -1) {
                System.out.println("Yes");
            } else {
                System.out.println("Noo");
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题