String的記憶體配置

來源:互聯網
上載者:User

標籤:

1、String類是final類不能被繼承

2、String str="abc"的內部工作

(1)先在棧中定 一個名為str的String類的引用變數 String str;

(2)在棧中尋找有沒有存放值為"abc的地址",如果沒有,則開闢一個存放字面值為"abc"的地址,接著建立一個新的String類的對象o,並將o的字串值指向這個地址,而且在棧中這個地址旁邊記下這個引用的對象o。如果已經有了值為"abc"的地址,則尋找對象o,並返回o的地址。

(3)將str指向對象o的地址。

3、String str = new String("abc");

(1)在棧中定義String str

(2)在堆中建立對象 new String("abc")

(3)棧中的str指向堆中abc的地址

4、

static void testString(){        String a = "helloworld";        String b = new String("helloworld");        String c = "hello"+"world";        System.out.println(a==b);//false        System.out.println(a==c);//true        System.out.println(b==c);//false                System.out.println(a.equals(b));        System.out.println(a.equals(c));        System.out.println(c.equals(b));    }

String的記憶體配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.