Java 程序用于从字符串中删除首尾空白
使用 Trim() 方法来从字符串中删除首尾空白。假设我们在字符串的最开始和最后都存在空白。
String str = " a ";
现在,使用 trim() 方法。
str.trim()
这以下是最终的示例和输出。
示例
public class Demo { public static void main(String[] args) { String str = " a "; System.out.println("Text = "+str); System.out.println("Text after using trim() method = " + str.trim()); } }
输出
Text = a Text after using trim() method = a
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP