public
String(byte bytes[], Charset charset)
Constructs a new String
by decoding the specified array of bytes using the specified charset.
The length of the new String is a function of the charset, and hence
may not be equal to the length of the byte array.
import java.nio.charset.*; import java.util.*; class StringConstructor3{ public static void main(String args[]){ byte data[] = new byte[26]; String s1; int count = 0; SortedMap<String, Charset> myMap; Set<String> keys; for(byte b = 97; b < 123; b++){ data[count] = b; count++; } myMap = Charset.availableCharsets(); keys = myMap.keySet(); System.out.println("Encoding\tString\t\t\tlength"); Iterator<String> i = keys.iterator(); while (i.hasNext()) { String key = i.next(); Charset chSet = myMap.get(key); String enc = chSet.displayName(); s1 = new String(data, chSet); System.out.println(enc +"\t" +s1 +"\t"+s1.length()); } } }
Output
Encoding String length Big5 abcdefghijklmnopqrstuvwxyz 26 Big5-HKSCS abcdefghijklmnopqrstuvwxyz 26 CESU-8 abcdefghijklmnopqrstuvwxyz 26 EUC-JP abcdefghijklmnopqrstuvwxyz 26 EUC-KR abcdefghijklmnopqrstuvwxyz 26 GB18030 abcdefghijklmnopqrstuvwxyz 26 GB2312 abcdefghijklmnopqrstuvwxyz 26 GBK abcdefghijklmnopqrstuvwxyz 26 IBM-Thai /???????^?,%_>??????????`: 26 IBM00858 abcdefghijklmnopqrstuvwxyz 26 IBM01140 /?Ä???ÅÇÑ?,%_>??É???????`: 26 IBM01141 /?[???ÅÇÑö,%_>??É???????`: 26 IBM01142 /?Ä???$ÇÑ?,%_>??É???????`: 26 IBM01143 /?#???$ÇÑö,%_>??\???????é: 26 IBM01144 /?Ä???ÅÇÑò,%_>??É???????ù: 26 IBM01145 /?Ä???ÅÇ#ñ,%_>??É???????`: 26 IBM01146 /?Ä???ÅÇÑ?,%_>??É???????`: 26 IBM01147 /?Ä???ÅÇÑù,%_>??É???????µ: 26 IBM01148 /?Ä???ÅÇÑ?,%_>??É???????`: 26 IBM01149 /?Ä???ÅÇÑ?,%_>??É????????: 26 IBM037 /?Ä???ÅÇÑ?,%_>??É???????`: 26 IBM1026 /?Ä???Å[Ñ?,%_>??É????????: 26 IBM1047 /?Ä???ÅÇÑ?,%_>??É???????`: 26 IBM273 /?[???ÅÇÑö,%_>??É???????`: 26 IBM277 /?Ä???$ÇÑ?,%_>??É???????`: 26 IBM278 /?#???$ÇÑö,%_>??\???????é: 26 IBM280 /?Ä???ÅÇÑò,%_>??É???????ù: 26 IBM284 /?Ä???ÅÇ#ñ,%_>??É???????`: 26 IBM285 /?Ä???ÅÇÑ?,%_>??É???????`: 26 IBM290 /abcdefgh?,%_>?[ijklmnop`: 26 IBM297 /?Ä???ÅÇÑù,%_>??É???????µ: 26 IBM420 /?????????,%_>???????????: 26 IBM424 /?????????,%_>????? ????`: 26 IBM437 abcdefghijklmnopqrstuvwxyz 26 IBM500 /?Ä???ÅÇÑ?,%_>??É???????`: 26 IBM775 abcdefghijklmnopqrstuvwxyz 26 IBM850 abcdefghijklmnopqrstuvwxyz 26 IBM852 abcdefghijklmnopqrstuvwxyz 26 IBM855 abcdefghijklmnopqrstuvwxyz 26 IBM857 abcdefghijklmnopqrstuvwxyz 26 IBM860 abcdefghijklmnopqrstuvwxyz 26 IBM861 abcdefghijklmnopqrstuvwxyz 26 IBM862 abcdefghijklmnopqrstuvwxyz 26 IBM863 abcdefghijklmnopqrstuvwxyz 26 IBM864 abcdefghijklmnopqrstuvwxyz 26 IBM865 abcdefghijklmnopqrstuvwxyz 26 IBM866 abcdefghijklmnopqrstuvwxyz 26 IBM868 abcdefghijklmnopqrstuvwxyz 26 IBM869 abcdefghijklmnopqrstuvwxyz 26 IBM870 /?Ä????Ç?|,%_>??É???????`: 26 IBM871 /?Ä???ÅÇÑ?,%_>??É????????: 26 IBM918 /????????`,%_>???????????: 26 ISO-2022-CN abcdefghijklmnopqrstuvwxyz 26 ISO-2022-JP abcdefghijklmnopqrstuvwxyz 26 ISO-2022-JP-2 abcdefghijklmnopqrstuvwxyz 26 ISO-2022-KR abcdefghijklmnopqrstuvwxyz 26 ISO-8859-1 abcdefghijklmnopqrstuvwxyz 26 ISO-8859-13 abcdefghijklmnopqrstuvwxyz 26 ISO-8859-15 abcdefghijklmnopqrstuvwxyz 26 ISO-8859-2 abcdefghijklmnopqrstuvwxyz 26 ISO-8859-3 abcdefghijklmnopqrstuvwxyz 26 ISO-8859-4 abcdefghijklmnopqrstuvwxyz 26 ISO-8859-5 abcdefghijklmnopqrstuvwxyz 26 ISO-8859-6 abcdefghijklmnopqrstuvwxyz 26 ISO-8859-7 abcdefghijklmnopqrstuvwxyz 26 ISO-8859-8 abcdefghijklmnopqrstuvwxyz 26 ISO-8859-9 abcdefghijklmnopqrstuvwxyz 26 JIS_X0201 abcdefghijklmnopqrstuvwxyz 26 JIS_X0212-1990 ??????????????????? 19 KOI8-R abcdefghijklmnopqrstuvwxyz 26 KOI8-U abcdefghijklmnopqrstuvwxyz 26 Shift_JIS abcdefghijklmnopqrstuvwxyz 26 TIS-620 abcdefghijklmnopqrstuvwxyz 26 US-ASCII abcdefghijklmnopqrstuvwxyz 26 UTF-16 ????????????? 13 UTF-16BE ????????????? 13 UTF-16LE ????????????? 13 UTF-32 ??????? 7 UTF-32BE ??????? 7 UTF-32LE ??????? 7 UTF-8 abcdefghijklmnopqrstuvwxyz 26 windows-1250 abcdefghijklmnopqrstuvwxyz 26 windows-1251 abcdefghijklmnopqrstuvwxyz 26 windows-1252 abcdefghijklmnopqrstuvwxyz 26 windows-1253 abcdefghijklmnopqrstuvwxyz 26 windows-1254 abcdefghijklmnopqrstuvwxyz 26 windows-1255 abcdefghijklmnopqrstuvwxyz 26 windows-1256 abcdefghijklmnopqrstuvwxyz 26 windows-1257 abcdefghijklmnopqrstuvwxyz 26 windows-1258 abcdefghijklmnopqrstuvwxyz 26 windows-31j abcdefghijklmnopqrstuvwxyz 26 x-Big5-HKSCS-2001 abcdefghijklmnopqrstuvwxyz 26 x-Big5-Solaris abcdefghijklmnopqrstuvwxyz 26 x-euc-jp-linux abcdefghijklmnopqrstuvwxyz 26 x-EUC-TW abcdefghijklmnopqrstuvwxyz 26 x-eucJP-Open abcdefghijklmnopqrstuvwxyz 26 x-IBM1006 abcdefghijklmnopqrstuvwxyz 26 x-IBM1025 /????????|,%_>??????????`: 26 x-IBM1046 abcdefghijklmnopqrstuvwxyz 26 x-IBM1097 /?????????,%_>??????????`: 26 x-IBM1098 abcdefghijklmnopqrstuvwxyz 26 x-IBM1112 /?Ä???Å???,%_>??É???????`: 26 x-IBM1122 /?#???$ÇÑö,%_>??\???????é: 26 x-IBM1123 /????????|,%_>??????????`: 26 x-IBM1124 abcdefghijklmnopqrstuvwxyz 26 x-IBM1364 /?????????,%_>?[????????`: 26 x-IBM1381 abcdefghijklmnopqrstuvwxyz 26 x-IBM1383 abcdefghijklmnopqrstuvwxyz 26 x-IBM300 ????????????? 13 x-IBM33722 abcdefghijklmnopqrstuvwxyz 26 x-IBM737 abcdefghijklmnopqrstuvwxyz 26 x-IBM833 /?????????,%_>?[????????`: 26 x-IBM834 ???????????????????? 20 x-IBM856 abcdefghijklmnopqrstuvwxyz 26 x-IBM874 abcdefghijklmnopqrstuvwxyz 26 x-IBM875 /??Φ??Ω??|,%_>????? ????`: 26 x-IBM921 abcdefghijklmnopqrstuvwxyz 26 x-IBM922 abcdefghijklmnopqrstuvwxyz 26 x-IBM930 /abcdefgh?,%_>?[ijklmnop`: 26 x-IBM933 /?????????,%_>?[????????`: 26 x-IBM935 /?????????,%_>??????????`: 26 x-IBM937 /?????????,%_>??????????`: 26 x-IBM939 /?????????,%_>??????????`: 26 x-IBM942 abcdefghijklmnopqrstuvwxyz 26 x-IBM942C abcdefghijklmnopqrstuvwxyz 26 x-IBM943 abcdefghijklmnopqrstuvwxyz 26 x-IBM943C abcdefghijklmnopqrstuvwxyz 26 x-IBM948 abcdefghijklmnopqrstuvwxyz 26 x-IBM949 abcdefghijklmnopqrstuvwxyz 26 x-IBM949C abcdefghijklmnopqrstuvwxyz 26 x-IBM950 abcdefghijklmnopqrstuvwxyz 26 x-IBM964 abcdefghijklmnopqrstuvwxyz 26 x-IBM970 abcdefghijklmnopqrstuvwxyz 26 x-ISCII91 abcdefghijklmnopqrstuvwxyz 26 x-ISO-2022-CN-CNS abcdefghijklmnopqrstuvwxyz 26 x-ISO-2022-CN-GB abcdefghijklmnopqrstuvwxyz 26 x-iso-8859-11 abcdefghijklmnopqrstuvwxyz 26 x-JIS0208 ???????????????? 16 x-JISAutoDetect abcdefghijklmnopqrstuvwxyz 26 x-Johab abcdefghijklmnopqrstuvwxyz 26 x-MacArabic abcdefghijklmnopqrstuvwxyz 26 x-MacCentralEurope abcdefghijklmnopqrstuvwxyz 26 x-MacCroatian abcdefghijklmnopqrstuvwxyz 26 x-MacCyrillic abcdefghijklmnopqrstuvwxyz 26 x-MacDingbat ?????????????■???????????? 26 x-MacGreek abcdefghijklmnopqrstuvwxyz 26 x-MacHebrew abcdefghijklmnopqrstuvwxyz 26 x-MacIceland abcdefghijklmnopqrstuvwxyz 26 x-MacRoman abcdefghijklmnopqrstuvwxyz 26 x-MacRomania abcdefghijklmnopqrstuvwxyz 26 x-MacSymbol α??δεφ?????????π??στ?????? 26 x-MacThai abcdefghijklmnopqrstuvwxyz 26 x-MacTurkish abcdefghijklmnopqrstuvwxyz 26 x-MacUkraine abcdefghijklmnopqrstuvwxyz 26 x-MS932_0213 abcdefghijklmnopqrstuvwxyz 26 x-MS950-HKSCS abcdefghijklmnopqrstuvwxyz 26 x-MS950-HKSCS-XP abcdefghijklmnopqrstuvwxyz 26 x-mswin-936 abcdefghijklmnopqrstuvwxyz 26 x-PCK abcdefghijklmnopqrstuvwxyz 26 x-SJIS_0213 abcdefghijklmnopqrstuvwxyz 26 x-UTF-16LE-BOM ????????????? 13 X-UTF-32BE-BOM ??????? 7 X-UTF-32LE-BOM ??????? 7 x-windows-50220 abcdefghijklmnopqrstuvwxyz 26 x-windows-50221 abcdefghijklmnopqrstuvwxyz 26 x-windows-874 abcdefghijklmnopqrstuvwxyz 26 x-windows-949 abcdefghijklmnopqrstuvwxyz 26 x-windows-950 abcdefghijklmnopqrstuvwxyz 26 x-windows-iso2022jp abcdefghijklmnopqrstuvwxyz 26
No comments:
Post a Comment