/*转换primitive主数据类型
* 短变长直接转换
* 长变短要强制转换
* 例如:long y = 42; int x = (int)y
* String类型转换成primitive类型时可以通过系统内置的类实现
* 例如:String value = "33";int x = Integer.parseInt(value);
* 调用了Integer类型的静态方法parseInt();*/
1 public class Zhuanhuan { 2 public static void main(String[] args){ 3 long max = 1000; 4 short m = (short)max; 5 System.out.println("转换之后的max值是:"+m); 6 7 float f = 5.123f; 8 int f1 = (int)f; 9 System.out.println("转换之后的f值是:"+f1); 10 11 String num = "23"; 12 int n = Integer.parseInt(num);// Integer为JAVA内置的类,parse为静态方法 13 System.out.println("转换之后的num值是:"+n); 14 } 15 16 }