码迷,mamicode.com
首页 > 编程语言 > 详细

java9新特性-11-String存储结构变更

时间:2018-01-13 11:12:46      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:img   eps   hal   operation   pos   for   which   shu   fst   

1. 官方Feature

JEP254: Compact Strings

 


2. 产生背景

Motivation

The current implementation of the String classstores characters in a char array,using two bytes (sixteen bits) for each character. Data gathered from manydifferent applications indicates that strings are a major component of heapusage and, moreover, that most String objectscontain only Latin-1 characters. Such characters require only one byte ofstorage, hence half of the space in the internal char arraysof such String objects is going unused.

 


3. 使用说明

Description

We propose to change the internal representation of the Stringclass from a UTF-16 char array to a byte array plus an encoding-flag field. The new String class will store characters encoded either as ISO-8859-1/Latin-1 (one byte per character), or as UTF-16 (two bytes per character), based upon the contents of the string. The encoding flag will indicate which encoding is used.

?结论:String 再也不用 char[] 来存储啦,改成了 byte[] 加上编码标记,节约了一些空间。

 

 
技术分享图片
 

 


4. 拓展:StringBuffer 与StringBuilder

那StringBuffer 和 StringBuilder 是否仍无动于衷呢?

?String-related classes such as AbstractStringBuilder, StringBuilder, and StringBuffer will

be updated to use the same representation, as will the HotSpot VM‘s intrinsic string operations.



作者:尚硅谷面试官宋红康
链接:https://www.jianshu.com/p/39ae521056c2
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

java9新特性-11-String存储结构变更

标签:img   eps   hal   operation   pos   for   which   shu   fst   

原文地址:https://www.cnblogs.com/wzlbigdata/p/8278392.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!