62,615
社区成员
发帖
与我相关
我的任务
分享
char ch = '我';
System.out.println(ch+" "+ch.SIZE+" "+String.valueOf(ch).getBytes("UNICODE").length+" UNICODE");
public class CharacterDemo {
public static void main(String[] args) throws IOException {
String str = "我";
for(int i=0;i<str.length();i++){
Character ch = str.charAt(i);
System.out.println(ch+" "+ch.SIZE+" "+String.valueOf(ch).getBytes("UNICODE").length);
System.out.println(byteToHex(String.valueOf(ch).getBytes("UNICODE")));
}
}
public static String byteToHex(byte [] bytes){
StringBuilder sb = new StringBuilder(4);
for (int b : bytes) {
sb.append(Integer.toHexString(b & 0x00FF | 0xFF00).substring(2, 4).toUpperCase());
sb.append(" ");
}
return sb.toString();
}
}