标签:odi sys src har 图片 pre import close charset
初稿:2017-11-19 23:57:11
1 import java.nio.charset.Charset; 2 import java.io.UnsupportedEncodingException; 3 4 public class StringContructorTest { 5 6 public static void main(String[] args) { 7 testStringConstructors() ; 8 } 9 private static void testStringConstructors() { 10 try { 11 System.out.println("------------------------ testStringConstructors -----------------------"); 12 13 String str01 = new String(); 14 String str02 = new String("String02"); 15 String str03 = new String(new char[]{‘s‘,‘t‘,‘r‘,‘0‘,‘3‘}); 16 String str04 = new String(new char[]{‘s‘,‘t‘,‘r‘,‘0‘,‘4‘}, 1, 3); 17 String str05 = new String(new StringBuffer("StringBuffer")); 18 String str06 = new String(new StringBuilder("StringBuilder")); 19 String str07 = new String(new byte[]{0x61, 0x62, 0x63, 0x64, 0x65}); 20 // 0x61在ASC表中,对应字符"a"; 1表示起始位置,3表示长度 21 String str08 = new String(new byte[]{0x61, 0x62, 0x63, 0x64, 0x65}, 1, 3); 22 // 0x61在ASC表中,对应字符"a"; 1表示起始位置,3表示长度 23 String str09 = new String(new byte[]{(byte)0xe5, (byte)0xad, (byte)0x97, 24 (byte)0xe7, (byte)0xac, (byte)0xa6, 25 (byte)0xe7, (byte)0xbc, (byte)0x96, 26 (byte)0xe7, (byte)0xa0, (byte)0x81}, 27 0, 12, "utf-8"); // 0表示起始位置,12表示长度。 28 String str10 = new String(new byte[]{(byte)0x5b, (byte)0x57, 29 (byte)0x7b, (byte)0x26, 30 (byte)0x7f, (byte)0x16, 31 (byte)0x78, (byte)0x01}, 32 0, 8, "utf-16"); // 0表示起始位置,8表示长度。 33 String str11 = new String(new byte[]{(byte)0xd7, (byte)0xd6, 34 (byte)0xb7, (byte)0xfb, 35 (byte)0xb1, (byte)0xe0, 36 (byte)0xc2, (byte)0xeb}, 37 Charset.forName("gb2312")); 38 String str12 = new String(new byte[]{(byte)0xd7, (byte)0xd6, 39 (byte)0xb7, (byte)0xfb, 40 (byte)0xb1, (byte)0xe0, 41 (byte)0xc2, (byte)0xeb}, 42 0, 8, Charset.forName("gbk")); 43 String str13 = new String(new int[] {0x5b57, 0x7b26, 0x7f16, 0x7801},0,4); 44 //"字符编码"(\u5b57是‘字’的unicode编码)。0表示起始位置,4表示长度。 45 System.out.println("str01 = " + str01); 46 System.out.println("str02 = " + str02); 47 System.out.println("str03 = " + str03); 48 System.out.println("str04 = " + str04); 49 System.out.println("str05 = " + str05); 50 System.out.println("str06 = " + str06); 51 System.out.println("str07 = " + str07); 52 System.out.println("str08 = " + str08); 53 System.out.println("str09 = " + str09); 54 System.out.println("str10 = " + str10); 55 System.out.println("str11 = " + str11); 56 System.out.println("str12 = " + str12); 57 System.out.println("str13 = " + str13); 58 } catch (UnsupportedEncodingException e) { 59 e.printStackTrace(); 60 } 61 } 62 }
标签:odi sys src har 图片 pre import close charset
原文地址:http://www.cnblogs.com/joyeehe/p/7863009.html