本文介绍了什么是Java的内部代表String?修改UTF-8? UTF-16?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



一个是:

,它说:

另一个是:

,它说:

修改的UTF-8?还是UTF-16?哪一个是正确的? Java在内存中使用多少字节?



请让我知道哪一个是正确的,它使用了多少个字节。

解决方案

Java中String和StringBuilder等的表示是UTF-16



序列化字符串默认使用UTF-8。

and it says:

The other is:

and it says:

Modified UTF-8? Or UTF-16? Which one is correct? And how many bytes does Java use for a char in memory?

Please let me know which one is correct and how many bytes it uses.

解决方案

The representation for String and StringBuilder etc in Java is UTF-16

http://java.sun.com/javase/technologies/core/basic/intl/faq.jsp

At the JVM level, if you are using -XX:+UseCompressedStrings (which is default for some updates of Java 6) The actual in-memory representation can be 8-bit, ISO-8859-1 but only for strings which do not need UTF-16 encoding.

http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

Serialized Strings use UTF-8 by default.

A char is always two bytes, if you ignore the need for padding in an Object.

Note: a code point (which allows character > 65535) can use one or two characters, i.e. 2 or 4 bytes.

这篇关于什么是Java的内部代表String?修改UTF-8? UTF-16?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 23:30