2017.7.19(代码块,包装类,基本类型与String互转)

来源:互联网 发布:js高级函数 编辑:程序博客网 时间:2024/06/02 04:14


代码块是一种常见的代码形式。用大括号“{}”将多行代码封装在一起,形成一个独立的代码区,这就构成了代码块

static {    System.out.println("这是一个静态代码块");}{    System.out.println("这是一个普通代码块");}
八大包装类
基本类型共有八种,它们分别都有相对应的包装类。
short     Short  int       Integer  
long      Long    float     Float    double    Double   byte      Byte   char      Characterboolean   Boolean
{    Integer i1 = 5;//自动装箱    Object booleanValue = true;//自动拆箱    int i2 = i1;    if (booleanValue instanceof Boolean) {        Boolean b1 = (Boolean) booleanValue;        boolean b2 = (Boolean) booleanValue;        System.out.println(b1.booleanValue());        System.out.println(b2);    }    System.out.println(i1);    System.out.println(i2);
基本类型与String互转
int i4 = 15;String s1 = String.valueOf(i4);//int 转StringString s2 = i4+"";//int 转StringString s = "123";//字符串转基本类型int i3 = Integer.parseInt(s);double d1 = Double.parseDouble(s);long l1 = Long.parseLong(s);float f1 = Float.parseFloat(s);System.out.println(i3);
原创粉丝点击