Java基本数据类型 包装类

java八大基本数据类型,都有与之对应的包装类

包装类能够实现实体化处理对象,有更多方法来处理当前的数据

整型类型:byte short int long

浮点类型: float double

字符型: char

布尔类型: boolean

int ==> Integer byte ==> Byte

short ==> Short long==>Long

float==>Float double==>Double

char==> Character boolean==>Boolean

[重点]:

  1. jdk1.5之后,有自动拆箱和自动装箱

    自动装箱: 将基本数据类型转为包装类

    int i = 30; Integer i1 = i;

    自动拆箱: 将包装类转为基本数据类型

  2. ***Value () ; 将包装类转为基本数据类型 手动拆箱(了解)

  3. toString(); 将基本是数据类型转为字符串

  4. parse***(); 将一个字符串 转为所对应的基本数据类型

    package com.qf.baozhuang;
    public class Demo01 {
        public static void main(String[] args) {
          // a();
          // b();
           //c();
           //d();
           e();
        }
        public static void a(){
            //一个持有最大值一个 int可以有2 31 -1。
            System.out.println(Integer.MAX_VALUE);
            //的常量保持的最小值的 int可以具有,-2 31。
            System.out.println(Integer.MIN_VALUE);
        }
        public static void b(){
            //1.自动装箱:  将基本数据类型转为包装类型
            int i = 10;
            Integer j = i;
            System.out.println(j);//10
            System.out.println(j.hashCode());//返回这个 Integer的哈希码   10
            //2.自动拆箱:  将包装类转为基本数据类型
            int i1 = j;
            System.out.println(i1);//10
        }
        public static void c(){
            //3.toString方法
            String s = Integer.toString(55);
            System.out.println(s);
        }
        public static void d(){
            //4.将字符串转为基本数据类型
            int i = Integer.parseInt("789");
            System.out.println(i);//789
            double v = Double.parseDouble("789.466");
            System.out.println(v);//789.466
        }
        public static void e(){
            Integer q1 = 50;
            Integer q2 = 50;
            System.out.println(q1 == q2); //true
            Integer o1 = 129;
            Integer o2 = 129;
            //面试考题 因为Integer的数值范围是-128~127;这是在一个数组内
            //超出这个范围值的话,就会new一个空间,地址将不一样
            System.out.println(o1 == o2); //false
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值