How much memory does a string use in Java 8?

前端 未结 4 1952
暖寄归人
暖寄归人 2020-11-30 03:18

I read a lot about memory allocation for Strings lately and can\'t find any details if things are the same with Java 8.

How much memory space would a String like

4条回答
  •  天涯浪人
    2020-11-30 03:44

    According to the following JEP: http://openjdk.java.net/jeps/254

    The current implementation of the String class stores characters in a char array, using two bytes (sixteen bits) for each character.

    In Java SE 9 this might change.

    Note however, since this is a JEP not a JSR (and it mentions implementation), I understand, that this is implementations specific and not defined by the JLS.

提交回复
热议问题