一、String trim方法:
public String trim()
**作用:**返回一个字符串,其值为此字符串,并删除任何前导和尾随空格。
如果此String对象表示一个空字符序列,或由该代表字符序列的第一个和最后一个字符String对象都具有代码大于’\u0020’ (空格字符),则此参考String被返回对象。
否则,如果字符串中没有字符大于’\u0020’的字符,则返回一个表示空字符串的String对象。
否则,令k为代码大于’\u0020’的字符串中第一个字符的’\u0020’ ,并且m为代码大于’\u0020’的字符串中最后一个字符的’\u0020’ 。将返回一个String对象,表示该字符串的子字符串,以索引k处的字符开头,以索引m为止的字符结束,结果为this.substring(k, m + 1) 。此方法可用于从字符串的开始和结尾修剪空格(如上定义)。
结果一个字符串,其值是此字符串,除去任何前导和尾随空格,或者如果该字符串没有前导或尾随的空格,则为该字符串。
二、相互转换
2.1、 int转换为String
// int转换为String
int i = 1;
String s1 = i+ "";
String s2 = Integer.toString(i);
String s3 = String.valueOf(i);
2.2、String转换为int
// String 转换成int型
int i1 = Integer.parseInt(s1);
int i2 = Integer.valueOf(s1).intValue();
2.3、Integer转换为String
// Integer转换成String
/*方法一:Integer类的静态方法toString()
* 方法二:Integer类的成员方法toString()
* 方法三:String类的静态方法valueOf()*/
// 一:
Integer a1 = 01;
String s4 = Integer.toString(a1);
// Three
Integer a3 = 3;
String s5 = String.valueOf(a3);
2.4、String 转换为Integer
// String 转换为Integer
Integer integer = Integer.valueOf(s1);
2.5、int 转换成Integer
// int 转换成Integer
Integer integer1 = new Integer(1);
2.6、Integer 转换为int
// Integer 转换为int
Integer A = new Integer(5);
int a =A.intValue();
2.7、String转化成BigDecimal
//把String转化成BigDecimal
BigDecimal bd = new BigDecimal(s1);