Java 中的字节_Java中的字节类

Byte类将原始类型byte的值包装在对象中。字节类型的对象包含一个类型为字节的字段。

以下是Byte类的一些方法-序号方法与说明1bytebyteValue()

此方法以字节形式返回此Byte的值。

2int compareTo(Byte anotherByte)

此方法以数字方式比较两个Byte对象。

3静态字节解码(String nm)

此方法将字符串解码为字节。

4doubledoubleValue()

此方法以double形式返回此Byte的值。

5boolean equals(Object obj)

此方法将此对象与指定对象进行比较。

6floatfloatValue()

此方法以浮点数形式返回此Byte的值。

7inthashCode()

此方法为此字节返回一个哈希码。

8intintValue()

此方法以int形式返回此Byte的值。

9longlongValue()

此方法返回此Byte的long值。

10静态字节parseByte(String s)

此方法将字符串参数解析为带符号的十进制字节。

现在让我们看一个例子-

示例import java.lang.*;

public class Demo {

public static void main(String[] args){

Byte b1, b2;

int i1, i2;

b1 = new Byte("1");

b2 = new Byte("-1");

i1 = b1.intValue();

i2 = b2.intValue();

String str1 = "int value of Byte " + b1 + " is " + i1;

String str2 = "int value of Byte " + b2 + " is " + i2;

System.out.println( str1 );

System.out.println( str2 );

}

}

输出结果int value of Byte 1 is 1

int value of Byte -1 is -1

示例

现在让我们来看另一个示例-import java.lang.*;

public class Demo {

public static void main(String[] args){

Byte b1, b2;

String s1, s2;

b1 = new Byte("-123");

b2 = new Byte("0");

s1 = b1.toString();

s2 = b2.toString();

String str1 = "String value of Byte " + b1 + " is " + s1;

String str2 = "String value of Byte " + b2 + " is " + s2;

System.out.println( str1 );

System.out.println( str2 );

}

}

输出结果String value of Byte -123 is -123

String value of Byte 0 is 0

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值