Confusion in Java 2
来源:互联网 发布:vncserver的端口 编辑:程序博客网 时间:2024/05/20 22:29
字符集的疑惑。
在《Java解惑》一书中提及默认字符集,即不指定字符集,进行类型转换所带来的“莫名其妙”。
书中示例代码:
byte bytes[] = new byte[256];
for(int i = 0; i<256; i++)
bytes[i] = (byte)i;
String str = new String(bytes);
for ( int i = 0; n = str.length(); i < n; i++)
System.out.print((int)str.charAt(i) + " "); [1]
这个运行结果在不同机器上可能有不同结果,原因是J2SE runtime 的默认字符集以来系统配置。
在JDK Doc中:
String(byte[] bytes)
Constructs a new String
by decoding the specified array of bytes using the platform's default charset.
所以使用:
String(byte[] bytes,Charset charset)
Constructs a new String
by decoding the specified array of bytes using the specifiedcharset.
这样可以保证转换的可控性。
- Confusion in Java 2
- Confusion in Java 1
- Confusion
- confusion
- lightoj 1374 Confusion in the Problemset
- lightoj 1374 - Confusion in the Problemset 贪心
- LightOJ - 1374 Confusion in the Problemset (模拟)
- UVALive 5963 Confusion in the Problem Set 思维题、Interesting
- Confusion Matrix
- Confusion Matrix
- Confusion Matrix
- Confusion Matrix
- UVALive 5963 (LA 5963) Confusion in the Problem Set 二分图匹配 (或 YY)
- To avoid user confusion, app version updates must utilize the iOS built-in update mechanism.
- linux grub confusion
- Confusion, diffusion, Collision, Substitution
- VS2003 Debuging confusion
- [zz]Dashboard Confusion
- 经典排序算法 – 插入排序Insertion sort
- 【行为模式】记录 (自己简短的理解,感觉理解了就记录下)
- 基于jquery的文件上传-uploadify资料收集
- 学一门语言需要的几个技能
- 经典排序算法 - 基数排序Radix sort
- Confusion in Java 2
- Linux查看进程状态(软件程序管理)
- 经典排序算法 - 鸽巢排序Pigeonhole sort
- 经典排序算法 - 归并排序Merge sort
- Mysql5.5管理
- 经典排序算法 - 冒泡排序Bubble sort
- HTML5表单之Input 类型-number
- git 教程
- 批处理 开启和关闭vmware