JavaSE8 base StringBuffer and string variables after appending a string, the address of the reference variable changes

Source: Internet
Author: User



Os:windows7 x64
Jdk:jdk-8u131-windows-x64
Ide:eclipse Oxygen Release (4.7.0)


Code

Package Jizuiku0;public class Demo11 {public static void main (string[] args) {String str1 = "Cnblog"; String str2 = str1 + "Jizuiku"; System.out.println (str1 = = str2); StringBuffer sb1 = new StringBuffer ("Cnblog");//create buffer a,a with cnblogstringbuffer SB2 = Sb1.append ("Jizuiku");// Append append to buffer A, buffer A is also buffer ASystem.out.println (SB1 = = SB2);//sb1, SB2 all point to buffer a}}


Result

Xjadcode (in order to find out what's going on here, use the Anti-compilation view):

Decompiled by Jad V1.5.8e2. Copyright 2001 Pavel kouznetsov.//Jad Home page:http://kpdus.tripod.com/jad.html//decompiler options:packimports (3) F Ieldsfirst ANSI Space//Source File Name:   demo11.javapackage Jizuiku0;import Java.io.printstream;public class Demo11{public Demo11 () {}public static void Main (string args[]) {string str1 = "Cnblog"; String str2 = (New StringBuilder (String.valueof (STR1)). Append ("Jizuiku"). ToString (); System.out.println (str1 = = str2); StringBuffer sb1 = new StringBuffer ("Cnblog"); StringBuffer SB2 = sb1.append ("Jizuiku"); System.out.println (SB1 = = SB2);}}

Look at the anti-compiled code, (⊙o⊙) Oh, the original is so compiled, understand!

Java is good, worth learning.
Learning resources: CZBK's video library. If you have public resources, can share to me, with your resources to learn also can.
Blog post is to watch the video, into thinking written. It's good that the teacher speaks well. Blog bad, is to give the most bitter not serious.

JavaSE8 base StringBuffer and string variables after appending a string, the address of the reference variable changes

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.