Created by Jerry Wang, last modified on Oct 06, 2016

Put this line into class main method:
String a = “i042416”;
And decompile the .class file using javap:

We can see the “i042416” is included in the constant pool:

The java code String a = “i042416” is implemented via two lines of codes below:

(1) When the class is loaded by JVM, the string “i042416” is represented by #16. When instruction ldc #16 is called for the first time, the native method StringTable::intern will be called to generate char[], and store the reference into StringTable and constant pool. When the ldc #16 is called subsequently, the reference #16 is directly returned from constant pool.

(2) Instruction astore_1 stores the reference of “i042416” to local variable table.
Test via these lines instead:
String aa1 = “i042416”;
String aa2 = “jerrywang”;
String aa3 = “i042416” + “jerrywang”;
We can see for line aa3, the string concatenation is done in compilation time.


As a result, the following println gets true as result:
String aa1 = “i042416jerrywang”;
String aa2 = “jerrywang”;
String aa3 = “i042416” + “jerrywang”;
System.out.println(aa1 == aa3);

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

使用javap工具分析Java String(字符串)操作相关推荐

  1. 使用javap分析Java的字符串操作

    我们看这样一行简单的字符串赋值操作的Java代码. String a = "i042416"; 使用命令行将包含了这行代码的Java类反编译查看其字节码: javap -v con ...

  2. Java String字符串长度不足指定位数补0

    Java String字符串长度不足指定位数补0 自己项目中有个需求:需要5位随机数-范围在1-99999 随机数可以利用Random()来获取,但是想要生成的随机数都是5位数,那就需要做一点小处理啦 ...

  3. string截取某个字符串之前的_python String字符串操作

    今天学习python的String字符串操作,并记录学习过程欢迎大家一起交流分享. 首先新建一个python文件命名为py3_string.py,在这个文件中进行字符串操作代码编写(如下为代码,文后有 ...

  4. java在字符串前后加引号,Java String字符串内容实现添加双引号

    Java String字符串内容实现添加双引号 作者: 91奔跑的蜗牛 更新时间:2020-09-12 15:45:46 原文链接 右侧开启环境实践本页内容 使用转义符 \ (反斜杠) String ...

  5. Java - String字符串的部分操作

    String转换为int String 字符串转整型 int 有以下两种方式: Integer.parseInt(str) Integer.valueOf(str).intValue() 注意:Int ...

  6. 【JVM】通过javap命令分析Java汇编指令

    文章目录 javap命令简述 javap测试及内容详解 例子1 例子2 总结 转载说明 javap命令简述 javap是jdk自带的反解析工具.它的作用就是根据class字节码文件,反解析出当前类对应 ...

  7. 润物无声:java的字符串操作

    说起字符串,真的是一个很容易被忽略(因为随时随地都在用,但是又不难),但是又非常重要.String类是Java中一个比较特殊的类,字符串即String类,它不是Java的基本数据类型之一,但可以像基本 ...

  8. Java String字符串和整型int的相互转换

    String 在编程中被广泛使用,所以掌握 String 和 int 的相互转换方法是极其重要的. String转换为int String 字符串转整型 int 有以下两种方式: Integer.pa ...

  9. Java教程:Java String字符串和整型int的相互转换

    Java教程String 在编程中被广泛使用,所以掌握 String 和 int 的相互转换方法是极其重要的.本节前面部分主要讲解了 String 转换 int 和 int 转换 String 方法, ...

最新文章

  1. imp 只导表前10条数据_Excel数据规范化10条原则,让你的工作效率快速提升
  2. Oracle11g的安装及配置
  3. 【数据结构与算法】之N个数中有K个数可能的组合算法
  4. 使用nginx部署简单的前端项目,nginx.conf配置
  5. ad软件侵权律师函_Aspen Plus 9 软件安装教程
  6. android studio ignore 模板,android studio git ignore
  7. python监控桌面捕捉_想要远程获取对方的桌面?Python教你一招搞定!
  8. DCL 管理用户 mysql
  9. map文件分析 stm32_使用STM32内部Flash额外的空间来存储数据
  10. 极限学习机︱R语言快速深度学习进行回归预测
  11. centos7安装便捷小工具命令
  12. 4个免费代码自动生成神器
  13. CAD图纸加密系统 - CAD2EXE V10.3
  14. 漏洞扫描工具之nessus
  15. 一小心删除了系统文件NTDETECT.COM怎么办
  16. 如何用vba把word文档的每页单独保存为一个word文档
  17. 绩效管理工具OKR与GRAD
  18. 国考计算机专业知识大纲,2021国考专业科目考试大纲(计算机类)考什么内容?...
  19. Android 代码中动态设置字体大小-TextView.SetTextSize()
  20. Docker 入门笔记 8 - Namespace 简介(中)

热门文章

  1. Cacti使用配置及FAQ
  2. Visual basic 6读写ini文件
  3. 一个实例告诉你Python中关于 if __name__ == ‘__main__‘ 有何作用
  4. url映射 ccf (Java正则表达式80分解法)
  5. 扩展WCF的消息分发行为
  6. sqlserver2012分页注意事项
  7. B-树 B+树复习总结
  8. poj2367 Genealogical tree
  9. ASP.NET MVC SSO单点登录设计与实现
  10. Date Picker和UITool Bar的使用