- public class T {
- public static void main(String [] args){
- //java 整型。
- byte b = 127;
- short s;
- int i;
- long l;
- //java字符型。
- char c;
- //符点型
- float f;
- double d;
- //布尔型
- boolean boo;
- //同类型的大类型转小类型将直接进行转换。
- s = b;i = b; l = b; f = b; d = b;
- //同类型小类型转大类型需要在前面进行转换
- b = (byte)d; s =(short) d; i = (int)d; l = (long)d; f = (float)d;
- //不同类型的转换
- c = (char)b;
- //对象之间的转换
- Long lo= new Long(1); //字数型
- String str = new String("1");
- lo = Long.valueOf(str);
- b = lo.byteValue();
- s = lo.shortValue();
- i = lo.intValue();
- l = lo.longValue();
- f = lo.floatValue();
- d = lo.doubleValue();
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/0112201411129.html
来源: http://www.codesnippet.cn/detail/0112201411129.html