Skip to content

Instantly share code, notes, and snippets.

@electrum
Created September 7, 2016 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electrum/ee0f9765ca91ee51b0406241f5dd24f6 to your computer and use it in GitHub Desktop.
Save electrum/ee0f9765ca91ee51b0406241f5dd24f6 to your computer and use it in GitHub Desktop.
Java String.getBytes() with Charset
[104, 101, 108, 108, 111]
[104, 101, 108, 108, 111]
[-2, -1, 0, 104, 0, 101, 0, 108, 0, 108, 0, 111]
[-120, -123, -109, -109, -106]
import java.nio.charset.Charset;
import java.util.Arrays;
public final class StringBytes
{
public static void main(String[] args)
{
bytes(Charset.forName("ASCII"));
bytes(Charset.forName("UTF-8"));
bytes(Charset.forName("UTF-16"));
bytes(Charset.forName("IBM500"));
}
private static void bytes(Charset charset)
{
System.out.println(Arrays.toString("hello".getBytes(charset)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment