字符串不能直接转为基本类型,但可以通过基本类型对应的包装类型进行转化
java为8种基本类型都提供了对应的包装类型:
byte—Byte
short—Short
int—Integer
long—Long
char—Character
float—Float
double—Double
boolean—Boolean
public class MyDemo7 {
public static void main(String[] args) {
boolean a = Boolean.parseBoolean("true");
System.out.println(a); //true
int i = Integer.parseInt("123");
System.out.println(i); //123
byte abc = Byte.parseByte("46");
System.out.println(abc); //46
long l = Long.parseLong("1515661515");
System.out.println(l); //1515661515
//......
}
}