java中的字符,字符串,数字之间的转换
string 和int之间的转换
string转换成int :Integer.PaseInt("12")
int转换成string : Integer.toString(12)
char和int之间的转换
首先将char转换成string
String str=String.valueOf('2')//String str = new String('2')
Integer.valueof(str) 或者Integer.PaseInt(str)
Integer.valueof返回的是Integer对象,Integer.paseInt返回的是int
char[] 与string的转换
char c[]=query.toCharArray();
byte[]与string
String query = request.getParameter("q");
byte b[] = query.getBytes("UTF-8");
trim():去掉字符串首尾的空格。
public static void main(String arg[]){
String a=" hello world ";
String b="hello world";
System.out.println(b.equals(a));
a=a.trim();//去掉字符串首尾的空格
System.out.println(a.equals(b));
}
执行结果:
a: hello world ,false
a:hello world,true
8096

被折叠的 条评论
为什么被折叠?



