美文网首页
java9新特性-11-String存储结构变更

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

作者: 程序员驴子酱 | 来源:发表于2018-01-04 22:34 被阅读0次

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.

相关文章

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

    1. 官方Feature JEP254:Compact Strings 2. 产生背景 Motivation Th...

  • java9的新特性

    1、Java9 新特性之---目录结构 包含jdk8及以前的jdk版本,所有目录结构以及目录含义如图: 这个新特性...

  • Java11的新特性

    Java语言特性系列 Java5的新特性 Java6的新特性 Java7的新特性 Java8的新特性 Java9的...

  • Java15的新特性

    Java语言特性系列 Java5的新特性 Java6的新特性 Java7的新特性 Java8的新特性 Java9的...

  • Java12的新特性

    Java语言特性系列 Java5的新特性 Java6的新特性 Java7的新特性 Java8的新特性 Java9的...

  • Java9 新特性官档翻译 (轻喷)

    Java9 新特性 翻译自 : https://docs.oracle.com/javase/9/whatsnew...

  • Java 9&10&11新特性

    Java9新特性 JDK和JRE目录结构的改变 1. 模块化系统 需要对外暴露的模块(后为需要暴露的文件所在包的路...

  • java9新特性

    1、模块化系统:Jigsaw->Modularity 解决越来越臃肿 的java运行环境。 主要目的在于减少...

  • Java9新特性

    作者:「Rambabu Posa」,一个具有 11 年丰富开发经验的技术牛人。 英文出处:Java 9 Featu...

  • Java9新特性

    Java 9 发布于 2017 年 9 月 22 日,带来了很多新特性,其中最主要的变化是已经实现的模块化系统。接...

网友评论

      本文标题:java9新特性-11-String存储结构变更

      本文链接:https://www.haomeiwen.com/subject/nqbdnxtx.html