?Java??????Unicode??????,??Java??????Unicode???
- ??
\u
?????Unicode??:
public class Main { public static void main(String[] args) { String str = "??, ??!"; // ??,??! System.out.println(str); } }
- ??
char
??????Unicode??:
public class Main { public static void main(String[] args) { char ch1 = '?'; // ? char ch2 = '?'; // ? System.out.println("" + ch1 + ch2); } }
- ??
String
?????????????????:
public class Main { public static void main(String[] args) { byte[] bytes = new byte[]{(byte) 0xE4, (byte) 0xBD, (byte) 0xA0, (byte) 0xE5, (byte) 0xA5, (byte) 0xBD}; // ???UTF-8?? try { String str = new String(bytes, "UTF-8"); System.out.println(str); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } }
- ??
String
??getBytes()
?????????????:
public class Main { public static void main(String[] args) { String str = "??"; try { byte[] bytes = str.getBytes("UTF-8"); for (byte b : bytes) { System.out.print(String.format("X ", b)); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } }
- ??
StringBuilder
?StringBuffer
???????????Unicode??????:
public class Main { public static void main(String[] args) { StringBuilder sb = new StringBuilder(); sb.appendCodePoint(0x4F60); // ? sb.appendCodePoint(0x597D); // ? System.out.println(sb.toString()); } }
??,Java????Unicode???,???????Unicode?????????????????????????(?UTF-8)???