Created
September 7, 2016 15:47
-
-
Save electrum/ee0f9765ca91ee51b0406241f5dd24f6 to your computer and use it in GitHub Desktop.
Java String.getBytes() with Charset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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