is string in Java fixed-length? Why "+" connection is available

Source: Internet
Author: User

The so-called length fixation is not what you understand.
instead, the char["stored in the string class] is final and cannot be modified, and your operation on string actually produces a new string, which is fixed for a string.

string s = "asdf"; When you define this variable, the Jvm-java virtual opportunity assigns a string constant ASDF to an address in the memory stack based on the Java object pooling mechanism, and you
You can refer to the J2SE API, and you will find that the variable of type string is
You cannot continue appending characters like StringBuffer (that is, after appending a character, it is not the original object).
So using the ' + ' hyphen s = s+ "X", the JVM then generates a new string constant on the stack.

is string in Java fixed-length? Why "+" connection is available

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.