Features:
(Recommended tutorial: java introductory tutorial)
1. The String class is modified by final. It cannot be inherited.
2. The underlying layer of the String class uses an array structure. Before jdk9, char[] was used, and after jdk9, byte[] was used.
3. Once a String object is created, it cannot be modified. A string constant pool is maintained at the bottom layer to achieve sharing.
Note: Every time an object of the String class is modified, a new object will be generated.
(Video tutorial recommendation: java video tutorial)
Splicing of String objects
String constants in the constant pool Strings in the constant pool Constant: The result is a string constant stored in the constant pool
String c = "a"+"b"; String ab = "ab"; System.err.println(ab==c); //输出true123
Variable constant pool: The result is a string constant stored in the heap
String a = "a"; String c = "a"+"b"; System.err.println(c==a+"b"); //输出false123
If the splicing result calls intern () method, the return value is in the constant pool
String a = "a"; String b = "b"; String c = "a"+"b"; System.err.println(c==a+b); //输出false,证明String类的拼接中只要有一个是变量,结果就存在堆中 String a = "a"; String b = "b"; String c = "a"+"b"; System.err.println(c==(a+b).intern()); //输出true,说明如果拼接结果调用intern()方法,返回值就在常量池中
The above is the detailed content of What are the characteristics of String class in java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment