1. Basic type----->String
1. toString() method of packaging class; such as: Short.toString(c);
2.String The valueOf() method of the class; such as:
2. String----->Basic type
1. The parseInt(str) method of the packaging class; such as: Integer.parseInt (str);
2. Valueof(str) method of packaging class; such as: Inteer.valueOf(str)
3. Code demonstration:
Test class: Test Code:
package com.bluesky; public class Test { public static void main(String[] args) { String str = "1314520"; int love = 520; //基本类型转换字符串 String str1=Integer.toString(love); //利用包装类的toString()方法; String str2=String.valueOf(love); //利用String类的valueOf()方法; System.out.println("str1="+str1); System.out.println("str2="+str2); //字符串转换基本类型 int love1=Integer.parseInt(str); //利用包装类的parseInt()方法; int love2=Integer.valueOf(str); //利用包装类的valueOf()方法; System.out.println("love1="+love1); System.out.println("love2="+love2); } }
The above is the content of conversion between basic types and strings in Java. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!