String.trim()
时间: 2023-11-12 13:14:07 浏览: 124
Js里面给String添加trim()方法,实现去掉字符串两边空格
3星 · 编辑精心推荐
The trim() method in Java is used to remove the leading and trailing white spaces (or any other characters) from a string.
For example, if we have a string " Hello World! " and use the trim() method, it will return "Hello World!" with the leading and trailing white spaces removed.
Syntax:
```
public String trim()
```
Example:
```
String str = " Hello World! ";
String trimmedStr = str.trim();
System.out.println(trimmedStr); // Output: "Hello World!"
```
阅读全文