java string结构_java9新特性-11-String存储结构变更

1. 官方Feature

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[] 加上编码标记,节约了一些空间。

8685e0700673a16aa9e2b89c4a9e6f79.png

4. 拓展:StringBuffer 与StringBuilder

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

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用以下步骤实现自动化针对两个文件夹下的同名文件做比较: 1. 首先,需要安装java-diff-utils库。可以通过Maven或Gradle等项目管理工具添加依赖项,或者手动下载jar包并添加到项目中。 2. 接下来,可以使用Java代码编写一个比较两个文件的方法。可以使用以下代码作为参考: ``` public static void compareFiles(File file1, File file2) { try { List<String> lines1 = FileUtils.readLines(file1, "UTF-8"); List<String> lines2 = FileUtils.readLines(file2, "UTF-8"); Patch patch = DiffUtils.diff(lines1, lines2); List<Delta> deltas = patch.getDeltas(); for (Delta delta : deltas) { System.out.println(delta); } } catch (IOException e) { e.printStackTrace(); } } ``` 这个方法接受两个File类型的参数,然后读取这两个文件的内容并比较它们。比较结果存储在一个Patch对象中,可以通过getDeltas()方法获取所有的变更。 3. 接下来,可以使用Katalon Studio编写一个测试用例,调用上述方法并执行比较操作。可以使用以下代码作为参考: ``` import java.io.File; import org.apache.commons.io.FileUtils; import org.junit.Test; public class FileComparisonTest { @Test public void testCompareFiles() { File folder1 = new File("path/to/folder1"); File folder2 = new File("path/to/folder2"); File[] files1 = folder1.listFiles(); for (File file1 : files1) { String filename = file1.getName(); File file2 = new File(folder2, filename); if (file2.exists()) { compareFiles(file1, file2); } else { System.out.println(filename + " not found in folder2"); } } } } ``` 这个测试用例会遍历第一个文件夹中的所有文件,然后检查第二个文件夹中是否有同名文件。如果有,就调用上述compareFiles()方法进行比较,否则输出文件不存在的消息。 注意,为了使用FileUtils类,需要在Katalon项目中添加commons-io库的依赖项。 4. 最后,可以在Katalon Studio中执行这个测试用例,自动化地比较两个文件夹下的同名文件。可以使用Katalon Studio提供的测试报告功能来查看比较结果和变更详情。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值