java 数组类型转换问题。
String str[3]={"0x2a","0x30","0x01"};
要转化成int num[3]={0x2a,0x30,0x01};
这个怎么转化啊。
求解!! 谢谢!~~
------解决方案--------------------这题目看的???迷惑
int num[]=Integer.parseInt(str); 试试
------解决方案--------------------public static void main(String [] args)
{
String str[]={"0x2a","0x30","0x01"};
int[] num = new int[str.length];
for(int i = 0; i < str.length; i++)
{
Byte b = Byte.decode(str[i]);
num[i] = toHexString(b);
}
System.out.println(Arrays.toString(num));
}
public static int toHexString(byte b)
{
int result=0;
result <<=8;
result|=(b&0xff);
return result;
}