一个小问题
下面是一段我自己设计的代码,目的是为了了解java.lang.Byte
public class Tbyte{ public static void main(String args[]){ Byte b1=new Byte("a"); int i1; i1=b1.intValue(); System.out.println(i1); }}
public class test { public static void main(String args[]) { Byte b1 = new Byte((byte)'a'); int i1; i1 = b1.intValue(); System.out.println(i1); }}
[解决办法]
String str = "127";//取值范围:"-128","-127",...."-2","-1","0","1","2",....,"126","127"Byte b1 = new Byte(str);//因为它只有八个二进制位,十进制形式为大于-128小于127int i1;i1 = b1.intValue();/*Constructs a newly allocated Byte object that represents the byte value indicated by the String parameter. The string is converted to a byte value in exactly the manner used by the parseByte method for radix 10. */