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

后端 未结 15 675
被撕碎了的回忆
被撕碎了的回忆 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:33

    Out of curiosity, is the few bytes saved really worth it?

    Normally, I suggest ditching strings for performance reasons, in favor of StringBuffer (Remember, Strings are immutable).

    Are you seriously exhausting your heap from string references?

提交回复
热议问题