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
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西