包装器类型学习(integer long short byte float double Boolean)

27 篇文章 0 订阅
4 篇文章 0 订阅

Boolean 类型

方法:

parseBoolean  //解析boolean
booleanValue //
valueOf       //转型
toString    //转字符串
hashCode      //hashicode
equals        //等于
getBoolean       
compareTo
compare

Byte 类型

方法

toString
valueOf
parseByte
decode
byteValue
shortValue
intValue
longValue
floatValue
doubleValue
hashCode
equals
compareTo
compare

Double 类型

方法:

toString
toHexString
valueOf
parseDouble
isNaN
isInfinite
isInfinite
byteValue
shortValue
intValue
longValue
floatValue
doubleValue
hashCode
equals
doubleToLongBits
compareTo
compare

Float 类

方法:

toString
toHexString
valueOf
parseFloat
isNaN
isInfinite
byteValue
shortValue
intValue
longValue
floatValue
doubleValue
hashCode
equals
floatToIntBits
compareTo
compare

Integer  类

方法:

toString
toHexString
toOctalString
toBinaryString
getChars
stringSize
parseInt
valueOf
byteValue
shortValue
intValue
longValue
floatValue
doubleValue
hashCode
equals
getInteger
decode
compareTo
compare
highestOneBit
lowestOneBit
numberOfLeadingZeros
numberOfTrailingZeros
bitCount
rotateLeft
rotateRight
reverse
signum
reverseBytes

Long  包装类

方法:

toString
toHexString
toOctalString
toBinaryString
getChars
parseLong
valueOf
decode
byteValue
shortValue
intValue
longValue
floatValue
doubleValue
hashCode
equals
getLong
compareTo
compare
highestOneBit
lowestOneBit
numberOfLeadingZeros
numberOfTrailingZeros
bitCount
rotateLeft
rotateRight
reverse
signum
reverseBytes

Short 包装类 

方法:

toString
parseShort
valueOf
decode
byteValue
shortValue
intValue
longValue
floatValue
doubleValue
hashCode
equals
compareTo
compare
reverseBytes

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java中提供了以下方法可以进行类型之间的转换: 1. 将基本数据类型转换为字符串: ```java byte b = 1; String strByte = Byte.toString(b); // byte 转换为字符串 short s = 2; String strShort = Short.toString(s); // short 转换为字符串 int i = 3; String strInt = Integer.toString(i); // int 转换为字符串 long l = 4L; String strLong = Long.toString(l); // long 转换为字符串 float f = 5.0f; String strFloat = Float.toString(f); // float 转换为字符串 double d = 6.0; String strDouble = Double.toString(d); // double 转换为字符串 char c = 'a'; String strChar = Character.toString(c); // char 转换为字符串 boolean bool = true; String strBool = Boolean.toString(bool); // boolean 转换为字符串 ``` 2. 将字符串转换为基本数据类型: ```java String str = "123"; byte b = Byte.parseByte(str); // 字符串转换为 byte short s = Short.parseShort(str); // 字符串转换为 short int i = Integer.parseInt(str); // 字符串转换为 int long l = Long.parseLong(str); // 字符串转换为 long float f = Float.parseFloat(str); // 字符串转换为 float double d = Double.parseDouble(str); // 字符串转换为 double char c = str.charAt(0); // 字符串转换为 char boolean bool = Boolean.parseBoolean(str); // 字符串转换为 boolean ``` 需要注意的是,在进行字符串转换成基本数据类型的时候,如果字符串的格式不符合相应数据类型的规范,会抛出NumberFormatException异常。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值