zoukankan      html  css  js  c++  java
  • [四]基础数据概述之Byte详解

     
     
    Byte 基本数据类型byte  的包装类
    Byte 类型的对象包含一个 byte类型的字段 
     
     
    image_5bb0643f_65ee
     
     
     

    属性简介

    image
     

    构造方法

    Byte的构造方法也是有两种
    可以通过基本类型byte   或者字符串形式
    Byte(byte value) image_5bb0643f_4fd9
    Byte(String s) image_5bb0643f_5c14
     
     

    常用方法

    比较

     
    static int compare(byte x, byte y) 静态方法
    x<y   小于0
    x=y   等于0
    x>y   大于0
    image_5bb0643f_7da1
    int compareTo(Byte anotherByte) 实例方法
    调用静态方法处理两个对象内部value的值
    image_5bb0643f_19ae
     

    parseXXX系列

    字符串解析 为 基本类型,
    不需要对象,所以都是静态方法
    image_5bb0643f_916
     
     
    static byte parseByte(String s, int radix)
    使用第二个参数指定的基数(进制),将字符串参数解析为有符号的整数
    除了第一个字符可以是用来表示负值的 ASCII 减号 '-' ('u002D’),加号'+' ('u002B')  外
    字符串中的字符必须都是指定基数的数字
    static byte parseByte(String s)  static byte parseByte(String s, int radix)的十进制简化形式
    image_5bb0643f_5f23
     

    valueOf系列

    把基本基本类型 包装为对象
    用来创建获得对象,所以无需对象,全都是静态方法
    image_5bb0643f_6362
     
    VaueOf系列都有对应的缓存区, 缓存区范围内对象为同一个 
    缓冲区为静态内部类中的数组 
    image_5bb0643f_29e1
     
    static Byte valueOf(byte b) 静态方法
    读取缓存中的对象 因为byte的取值范围就是-128 ~ 127
    所以所有对象都被缓存
    image_5bb0643f_6962
    static Byte valueOf(String s, int radix) 静态方法
    借助于parseByte将字符转变为byte  并且返回Byte对象
    image_5bb0643f_bd5
    static Byte valueOf(String s) 静态方法
    Byte valueOf(String s, int radix)的十进制简化形式

    image_5bb0643f_73c8
     

    decode

    Byte也提供了decode方法
    可以解析带有前缀的字符串
    实际使用的是Integer的decode
    然后将数值强转为byte
    image_5bb0643f_7d6a
     

    XXXValue系列

    获取对象的某种基本类型的值
    需要获取对象的所以必然全部都是实例方法
    image_5bb0643f_2d75
    强制类型转换的形式,将内部的  byte 值转换为指定的类型 
    类似 Integer和Long 
    Byte也有提供XXXValue系列方法,原理也跟他们类似
    全部都是强转
    byteValue()
    shortValue()
    intValue()
    longValue()
    floatValue()
    doubleValue()
     

    toString  toXXXString  系列

    static String toString(byte b) 静态方法
    image_5bb0643f_3901
    String toString()  实例方法
    image_5bb0643f_1fc8
    static int toUnsignedInt(byte x) 静态方法
    image_5bb0643f_79e0
    static long toUnsignedLong(byte x)  静态方法
    image_5bb0643f_3c
     

    hashcode

    static int hashCode(byte value) 静态方法
    image_5bb0643f_2f70
    int hashCode() 实例方法
    同Integer和Long一样,调用的静态方法的形式
    image_5bb0643f_1a69
     

    equals(Object)

     
    重写了equals方法
    内部比较的是对象的值
    image_5bb0643f_5f75
     
     
    可以看得出来,Byte中的方法相对于Integer和Long少了很多
    而且有些还是借助于Integer中的方法
     
  • 相关阅读:
    [BJOI2019] 光线
    C# 从零开始写 SharpDx 应用 笔刷
    BAT 脚本判断当前系统是 x86 还是 x64 系统
    BAT 脚本判断当前系统是 x86 还是 x64 系统
    win2d 通过 CanvasActiveLayer 画出透明度和裁剪
    win2d 通过 CanvasActiveLayer 画出透明度和裁剪
    PowerShell 拿到显卡信息
    PowerShell 拿到显卡信息
    win10 uwp 如何使用DataTemplate
    win10 uwp 如何使用DataTemplate
  • 原文地址:https://www.cnblogs.com/noteless/p/9729292.html
Copyright © 2011-2022 走看看