class test
{
public static void main(String[] args)
{
String a = "45";
int A = Integer.parseInt(a);
System.out.println(A);
String b = "true";
boolean B = Boolean.parseBoolean(b);
System.out.println(B);
String c = "1";
byte C = Byte.parseByte(c);
System.out.println(C);
String d = "30";
short D = Short.parseShort(d);
System.out.println(D);
String e = "99999999999";
long E = Long.parseLong(e);
System.out.println(E);
//String f = "y";
//char F = Character.parseChar(f);//string转换为char没有这个方法,可以用char a = str.CharAt(index);或char[] strChar = str.toCharArray();
//System.out.println(F);
String g = "2.8778";
float G = Float.parseFloat(g);
System.out.println(G);
String h = "3.788776655555";
double H = Double.parseDouble(h);
System.out.println(H);
}
}
java中String类型转换成基本数据类型总结
最新推荐文章于 2024-07-11 16:04:59 发布