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
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

最新文章

  1. firebug不能加载JS文件 ,无法进行JS脚本调试
  2. SQL 数据分页查询
  3. 10分钟学会理解和解决MySQL乱码问题
  4. scala中的抽象类
  5. 【java基础】 如何导入外部jar包
  6. bzoj1040
  7. artdialog关闭弹出窗口
  8. hdu2066一个人的旅行(dijkstra)
  9. Linux 终端下颜色的输出
  10. NanUI文档 - 使用网页来设计整个窗口
  11. PHP利用MySQL保存session
  12. crm 添加用户 编辑用户 公户和私户的展示,公户和私户的转化
  13. angular2监听页面大小变化
  14. if语句和case语句用法展示
  15. 自动化运维工具-pdsh工具安装配置及简单使用讲解
  16. Nginx+redis的Asp.net
  17. ios 向sqlite数据库插入和读取图片数据
  18. update pm storage
  19. 一个远程启动windows c++程序引发的技术决策现象
  20. mybatis的mapper返回map结果集(springboot)

热门文章

  1. hadoop系列:zookeeper(2)——zookeeper核心原理(选举)
  2. HDU 4175 Class Schedule (暴力+一点dp)
  3. Android recycleView的研究和探讨
  4. iOS:简单使用UIAlertVIew和UIActionSheet
  5. hdoj--1016--Prime Ring Problem(递归回溯)
  6. CentOS7安装第三方yum源EPEL
  7. 极客时间 mysql实战45讲下载读 08讲事务到底是隔离的还是不隔离的 笔记
  8. MYSQL INT(N)以及zerofill的使用区别
  9. 【算法】Bellman-Ford算法(单源最短路径问题)(判断负圈)
  10. wordpress 后台登录增加访问效验