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;
}
Your code looks a bit weird. You're mixing up values and representations of the values.
At this point you've got your correct int value. F.e. you typed 17 (of which you say it's a hex number). This int value now contains the value 23. Which is correct.
You can now store this value in your bytearray. And when you want to print it, you can use my code in order to represent it in a hex format.