基本数据类型对象包装类

基本数据类型包装类

/**
 * 基本数据类型对象包装类
 * 为了方便操作基本数据 类型值,将其封装成了对象 ,在对象中定义了属性和行为丰富了该数据的操作
 * 用于描述该对象 的类就称为基本数据 类型对象包装类
 * <p>
 * byte       Byte
 * short      Short
 * int        Integer
 * long       Long
 * float      Float
 * double     Double
 * char       Character
 * boolean    Boolean
 * <p>
 * 基本类型--->字符串
 * 1.基本类型数值+ “”
 * 2.用String类中的静态方法valueOf(基本类型数值)
 * 字符串--->基本类型
 * 1.使用包装类中的静态方法 xxx parseXxx("xxx类型的字符串")
 * int parseInt("intstring")
 * 只有Charcter没有这个方法
 * 2.如果字符串被Integer进行对象 的封装
 * 可使用另一个非静态的方法,intValue()
 * 将一外Integer对象转成基本数据类型值
 */
public class WrapperDemo {
    public static void main(String[] args) {
        Integer a = new Integer(127);
        Integer b = new Integer(127);
        System.out.println(a == b);//false
        System.out.println(a.equals(b));//ture

        Integer x = 127;
        Integer y = 127;
        System.out.println(x == y);//true
        System.out.println(x.equals(y));//true

        Integer aa = new Integer(128);
        Integer bb = new Integer(128);
        System.out.println(aa == bb);//false
        System.out.println(aa.equals(bb));//true

        Integer xx = 128;//jdk 1.5  以后,自动装箱,如果装箱的是一个字节,那么该 数据会被共享不会重新开辟空间
        Integer yy = 128;
        System.out.println(xx == yy);//false
        System.out.println(x.equals(yy));//false

        String s = "hello";
        String ss = "hello";
        String sss = new String("hello");
        System.out.println(s == ss);//true
        System.out.println(s.equals(ss));//true

        System.out.println(s == sss);//false
        System.out.println(s.equals(sss));//true

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值