I need to create a String from hex values I'm providing.
For example, instead of assigning like this:
String message = "123";
I want to assign like this:
String message = 0x31, 0x32, 0x33;
Is that possible?
You should probably also specify the character set you are using but this will do it:
String message = new String(new byte[] {0x31, 0x32, 0x33});
System.out.println(message); // prints 123.
If you did want to specify the character set it is just another parameter to the String
constructor. The following example will work if targeting Android API 19+:
String message = new String(new byte[] {0x31, 0x32, 0x33}, StandardCharsets.UTF_8);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With