前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[五]基础数据类型之Short详解

[五]基础数据类型之Short详解

作者头像
noteless
发布2018-10-10 11:31:13
1.8K0
发布2018-10-10 11:31:13
举报
文章被收录于专栏:noteless

Short 基本数据类型short  的包装类

Short 类型的对象包含一个 short 类型的字段

image_5bb07fe4_68cf[4]
image_5bb07fe4_68cf[4]

属性简介

值为  215-1 的常量,它表示 short 类型能够表示的最大值public static final short   MAX_VALUE = 32767;

值为 -215 的常量,它表示 short 类型能够表示的最小值public static final short   MIN_VALUE = -32768;

用来以二进制补码形式表示 short 值的比特位数public static final int SIZE = 16;

二进制补码形式表示 short 值的字节数public static final int BYTES = SIZE / Byte.SIZE;

表示基本类型 short 的 Class 实例public static final Class<Short>    TYPE = (Class<Short>) Class.getPrimitiveClass("short");

构造方法

照常两种形式 

基本类型/parseShort 按照10进制解析

Short(short value)

Short(String s)

常用方法

比较

static int compare(short x, short y) 静态方法 x<y   小于0 x=y   等于0 x>y   大于0

int compareTo(Short anotherShort)实例方法调用静态方法比较两个对象的值

parseXXX系列

字符串解析 为 基本类型,

不需要对象,所以都是静态方法

image_5bb07fe4_3f74[4]
image_5bb07fe4_3f74[4]

parseShort系列依赖Integer.parseInt

static short parseShort(String s, int radix)

static short parseShort(String s)

valueOf系列

把基本基本类型 包装为对象

用来创建获得对象,所以无需对象,全都是静态方法

image_5bb07fe4_67ee[3]
image_5bb07fe4_67ee[3]

VaueOf系列都有对应的缓存区, 缓存区范围内对象为同一个 

缓冲区为静态内部类中的数组  

image_5bb07fe4_b0[3]
image_5bb07fe4_b0[3]

缓冲范围为-128 ~ 127

static Short valueOf(short s)

static Short valueOf(String s, int radix)

static Short valueOf(String s)

decode

image_5bb07fe4_6637[3]
image_5bb07fe4_6637[3]

XXXValue系列

获取对象的某种基本类型的值

需要获取对象的所以必然全部都是实例方法

image_5bb07fe4_7709[3]
image_5bb07fe4_7709[3]

强制类型转换的形式,将内部的  short 值转换为指定的类型 

类似 Integer和Long    ByteShort也有提供XXXValue系列方法,原理也跟他们类似全部都是强转

byteValue() shortValue() intValue() longValue() floatValue() doubleValue()

toUnsignedXXX 系列

toString  系列

static String toString(short s)

String toString()

static int toUnsignedInt(short x)

static long toUnsignedLong(short x)

equals

重写了equals方法内部比较的是对象的值

hashCode

Short的hashcode 也是直接返回值

static int hashCode(short value)

int hashCode()

其他方法

Short提供了reverseBytes(short) 方法

Short虽然比Byte稍微提供的支持多一点点,但是也很少

有些方法也是依赖于Integer

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-09-30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档