基本类型转字符串
public class Demo01{
public static void main(String[]args){
int id = 150;
//用+号的方法
String str = id+"";
System.out.println(str);
//用toString的方法
int num = 100;
//用toString方法可以再转成某一个进制
String str1 = Integer.toString(num,8);//八进制
System.out.println(str1);
}
}
字符串转基本类型
//字符串类型转换成基本类型
//基本类型就是数字或者true或false,不可以出现不能转换的
String score = "120";
int out = Integer.parseInt(score);
System.out.println(out);
//boolean 字符串转基本 "true" 变true 非true就变false
String b1 = "true";
boolean b2 = Boolean.parseBoolean(b1);
System.out.println(b2);