I have String:
String str = "KITTEN";
And I would like to make a byte[] from it, but just:
byte[] mybyte = new byte[] { 'K', 'I', 'T', 'T', 'E', 'N'}
Anyone knows how to change String to that byte[]? Everything what I can find is about actual converting – please note that I don’t want to have hex representation of string.
PS. Title of question may be wrong – I’m sorry for that, didn’t know how to write it.
EDIT:
byte[] myBytes = str.getBytes();
Displaying:
byte[] display = new byte[] { 0x00, 0, 0, 'K', 'I', 'T'};
works, and displaying:
byte[] display = new byte[] { 0x00, 0, 0, myBytes[0], myBytes[1], myBytes[2] };
doesn’t work.
I try to display it on the screen of my device connected to the android phone by NFC. Do you know what’s make the problem?
getBytes() works for me:
Everything else what @Jon writes is still valid, as getBytes() is also doing a conversion:
Since using getBytes() introduces some platform dependencies, you should better explicitly pass an appropriate Charset: