1.包装类的tostring()方法; 如:short.tostring(c);
2.string类的valueof()方法;如:
二、字符串----->基本类型
1.包装类的parseint(str)方法; 如:integer.parseint(str);
2.包装类的valueof(str)方法; 如:inteer.valueof(str)
三、代码演示:
测试类:test代码:
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); } }
以上就是java中基本类型和字符串之间的转换的内容。
