假设我的一个byte[5]的数组,现在这个数组里存的是12345,怎么将这12345整体赋值给一个整型变量a啊?thanks

解决方案 »

  1.   

    byte[] b = new byte[]{1,2,3,4,5}
      

  2.   

    先把byte组合成字符串,再转换类型...例如Integer.valueOf(xxx)...
      

  3.   


    public class bbb
    {
    public static StringBuffer svalue=new StringBuffer("");
    public static void main(String[] args){
    byte[] b = new byte[]{1,2,3,4,5};

    int ivalue=0;
    for(int i=0;i<b.length;i++){
    //System.out.println(svalue);
    svalue.append(Byte.toString(b[i]));

    }
    ivalue = Integer.valueOf(new String(svalue));
    System.out.println(ivalue);
    }
    }---------- java run ----------
    12345输出完成 (耗时 0 秒) - 正常终止楼主是要这样的吗?