Is there a memory-efficient replacement of java.lang.String?

后端 未结 15 626
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 19:29

After reading this old article measuring the memory consumption of several object types, I was amazed to see how much memory Strings use in Java:



        
15条回答
  •  攒了一身酷
    2020-11-30 20:19

    Just compress them all with gzip. :) Just kidding... but I have seen stranger things, and it would give you much smaller data at significant CPU expense.

    The only other String implementations that I'm aware of are the ones in the Javolution classes. I don't think that they are more memory efficient, though:

    http://www.javolution.com/api/javolution/text/Text.html
    http://www.javolution.com/api/javolution/text/TextBuilder.html

提交回复
热议问题