String d = "Sweat D";
String e = "shout";
String f = "D";
System.out.println ("String length is" + d.length () + "." + d.getbytes ("GBK"). length
+ "bytes in GBK or" + d.getbytes ("UTF-8"). length
+ "bytes in UTF-8");
System.out.println ("Char array length is" + d.tochararray (). length);
System.out.println ("String length is" + e.length () + "." + e.getbytes ("GBK"). length
+ "bytes in GBK or" + e.getbytes ("UTF-8"). length
+ "bytes in UTF-8");
System.out.println ("Char array length is" + e.tochararray (). length);
System.out.println ("String length is" +f.length () + "." + f.getbytes ("GBK"). length
+ "bytes in GBK or" + f.getbytes ("UTF-8"). length
+ "bytes in UTF-8");
System.out.println ("Char array length is" + f.tochararray (). length);
SYSTEM.OUT.PRINTLN ("Default encoding is" +system.getproperty ("file.encoding"));
Output
String length is 2. 3 bytes in GBK or 4 bytes in UTF-8
Char array length is 2
String length is 1. 2 bytes in GBK or 3 bytes in UTF-8
Char array length is 1
String length is 1. 1 bytes in GBK or 1 bytes in UTF-8
Char array length is 1
Default encoding is UTF-8
Output-2
String length is 2. 3 bytes in GBK or 4 bytes in UTF-8
Char array length is 2
String length is 1. 2 bytes in GBK or 3 bytes in UTF-8
Char array length is 1
String length is 1. 1 bytes in GBK or 1 bytes in UTF-8
Char array length is 1
Default encoding is GBK
GBK Utf-8 string Java