Convert.ToByte(msg.Substring(i, 2), 16)如何用java表示?

private static byte[] hexToByte(string msg)
{
//msg = msg.Replace(" ", "");//移除空格
//定义一个长度1/2的数组comBuffer
byte[] comBuffer = new byte[msg.Length / 2];
//消息字符处理
for (int i = 0; i < msg.Length; i += 2)
{
comBuffer[i / 2] = (byte)Convert.ToByte(msg.Substring(i, 2), 16);
}
return comBuffer;
}
谁能将这段C#代码转为java,万分感谢!

虽然不懂C,但这段代码的意思应该是要把一个String 转为一个byte[]。如果是这个意思,那么JAVA里面可以:
private static byte[] hexToByte(String msg){
return msg.replace(" ", "").getBytes();
}