结果如图
package com.softeasy.test1; public class String_trim { public static void main(String[] args) { String str = " slkjfsj sdfjf jsjs "; System.out.println("没有用trim()方法前str为:|" + str + "|"); str = str.trim(); System.out.println("用了trim()方法后str为:|" + str + "|"); } }