Why is Java's String memory usage said to be high?

前端 未结 3 1071
不思量自难忘°
不思量自难忘° 2021-02-05 14:14

On this blog post, it\'s said that the minimum memory usage of a String is:

8 * (int) ((((no chars) * 2) + 45) / 8) bytes.

So for the String \"Apple

3条回答
  •  猫巷女王i
    2021-02-05 14:26

    Is it possible to save character data using less memory than a Java String? Yes.

    Does it matter for "enterprise" applications (or even Android or J2ME applications, which have to get by on a lot less memory)? Almost never.

    Premature optimization is the root...

提交回复
热议问题