Immutable String
String objects are immutable. The JVM has optimized it and opened up an area in the memory as a string constant pool. String objects created in "literal" form are cached and reused.
//"字面量"形式创建的字符串 String str = "abc";
String operator: " " and StringBuilder
operator " " can connect String strings. The compiler has an optimization measure. When compiling the source code and finding that all parameters of a calculation expression are literals, it will directly perform the calculation and compile the result into a class file.
String str = "abcd"; String str1 = "ab"+"cd";//输出abcd 对象不变 System.out.println(str==str1);//true
If one side of the calculation expression is a variable, then the compiler will splice it together during runtime and finally generate a new object, consuming performance.
String str = "abcd"; String str1 = "ab"; String str2 = str1+"cd";//输出abcd 对象改变 System.out.println(str==str2);//false
StringBuilder
The compiler will also automatically reference the append() method of StringBuilder for splicing during compilation, and finally call toString() to generate the result. However, each splicing loop in the .calss bytecode will create a StringBuilder object. If the string operation is complex, create a StringBuilder object for splicing when writing the .java file.
Common methods of String
The above is the detailed content of String_string. 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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)