Home > Java > javaTutorial > How to use strip function in Java?

How to use strip function in Java?

王林
Release: 2023-04-25 19:19:05
forward
2232 people have browsed it

1. Description

In the Java 11 release, a new strip() method has been added to remove prefix and suffix spaces from a String.

The reason for adding this method is that according to the Unicode standard, there are various space characters whose ASCII value is greater than 32 ('U 0020').

strip() can remove full-width and half-width whitespace characters before and after a string.

2. Example

public class StringStripTest {
    public static void main(String[] args) {
        String string = "    one    two    three    ";
        System.out.println("原始字符串: \"" + string+"\"");
        System.out.println("处理结果: \"" + string.strip()+"\"");
    }
}
Copy after login

What are the basic data types of java

The basic data types of Java are divided into:

1. Integer type, used to represent the data type of integers.

2. Floating point type, a data type used to represent decimals.

3. Character type. The keyword of character type is "char".

4. Boolean type is the basic data type that represents logical values.

The above is the detailed content of How to use strip function in Java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template