How can I find whitespace in a String?

后端 未结 14 1059
感动是毒
感动是毒 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:39

    Use org.apache.commons.lang.StringUtils.

    1. to search for whitespaces

    boolean withWhiteSpace = StringUtils.contains("my name", " ");

    1. To delete all whitespaces in a string

    StringUtils.deleteWhitespace(null) = null StringUtils.deleteWhitespace("") = "" StringUtils.deleteWhitespace("abc") = "abc" StringUtils.deleteWhitespace(" ab c ") = "abc"

提交回复
热议问题