for(int i = 0; i < size ; i++)
{
String str = scanner.next();
int x = Integer.parseInt(str,16);
String hexString = Integer.toHexString(x);
int y = Integer.parseInt(hexString,16);
byteArray[i] = (byte)y;
}
Jesper de Jong wrote:To see why you can't convert a byte to a char implicitly, look at this example. What value would you expect the char to have?
Manoj Kumar Jain wrote:Is it only the size that matters while passing/recieving the data ?
When you passing the short, while method is expecting the long type is fine because short is the type of int/long. so by implicite casting the program runs without any error.
but while you are passing the byte while method is expecting character is not correct because byte can't be cast in to a character.
So, this is not only the size that matters but also the type of data that you are passing. Instead of passing the short if you pass the character type to method and define the method like this
It will work fine because the char is of type Integer, so it can be cast to int type.