String构造函数
1> String()
2> String(char[] chars)
String(char[] chars,int startIndex,int numChars)
3> String(String strObj)
4> String(byte asciiChars[])
String(byte asciiChars[],int startIndex,int numChars)
2.整型、字符串相互转换
1> String -> int
(1)int i=Integer.parseInt(String s)
(2)int i=Integer.valueOf(str).intValue()
2>int -> String
(1)String s=String.valueOf(i)
(2)String s=Integer.toString(i)
(3)String s=””+i;
代码
//String --> int
String m_str="123";
int i=Integer.parseInt(m_str);
System.out.println("number is :"+(i+1));
i=Integer.valueOf(m_str);
System.out.println("number is :"+(i+2));
//String --> double
m_str="123.4";
Double d=Double.parseDouble(m_str);
System.out.println("number is :"+(d+3));
//int --> String
int j=321;
String s=String.valueOf(j);
System.out.println("string is :"+s+1);
s=Integer.toString(j);
System.out.println("string is :"+s+2);
s=""+j;
System.out.println("string is :"+s+3);
|