int -- String
? ? ? ?a:和""進(jìn)行拼接
? ? ? ?b:public static String valueOf(int i)
? ? ? ?c:int -- Integer -- String(Integer類的toString方法())
? ? ? ?d:public static String toString(int i)(Integer類的靜態(tài)方法)
String -- int
? ? ? a :String -- Integer -- int
? ? ? b:public static int parseInt(String s)
基本數(shù)據(jù)類型有八種呕缭,其中七種都有paseXxx的方法筑凫,可以將這七種的字符串表現(xiàn)形式轉(zhuǎn)換成基本數(shù)據(jù)類型
? ? ? ?//String s2 = "abc";
? ? ?//char c1 = Character.p? ? //char的包裝類Character沒有paseXxx方法?,字符串到字符的轉(zhuǎn)換通過tocharArray()可以將字符串轉(zhuǎn)換成字符數(shù)組
*/
public static void main(String[] args) {
? ? ? ? ? demo1();
private static void demo1() {
// int 轉(zhuǎn)化為 String
int i = 100;
String s1 = i + " ";? ? //推薦用
System.out.println(s1);
String s2 = String.valueOf(i);? //推薦用
System.out.println(s2);
Integer in = new Integer(i);
String s3 = in.toString();
System.out.println(s3);
String s4 = Integer.toString(i);
System.out.println(s4);
System.out.println("---------------");
//String 轉(zhuǎn)換為 int
String s5 = "100";
Integer in2 = new Integer(s5);
int i2 = in2.intValue();? ? ? ? //將Integer轉(zhuǎn)化為int
System.out.println(i2);
int i3 = Integer.parseInt(s5);? //將String轉(zhuǎn)換為int,推薦用這種
System.out.println(i3);
}
}