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

How to use strip function in Java?

王林
王林forward
2023-04-25 19:19:052136browse

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()+"\"");
    }
}

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete