去掉字符串首尾空格 防止不必要的空格导致错误public class test{ public static void main(String[] args) { String str = " abc "; System.out.println(str.length());//输出6 System.out.println(str.trim().length());//输出3 }}