Home >Java >javaTutorial >trim() function in Java

trim() function in Java

巴扎黑
巴扎黑Original
2016-11-26 09:07:352421browse

1. String .trim()

trim() removes leading and trailing spaces

2. str.replace(" ",""); removes all spaces, including leading and trailing spaces, and the middle

eg: String str = " hell o ";

              String str2 = str.replaceAll(" ","");

                     -- System.out.println(str2);

3, or replaceAll(" +".""); Remove all spaces

4. str = .replaceAll("\s*",""); can replace most whitespace characters, not limited to spaces

s can match any whitespace characters such as spaces, tabs, form feeds, etc. a


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Java 9 featuresNext article:Java 9 features