字串類為JAVA中的特殊類

來源:互聯網
上載者:User

標籤:因此   public   ==   字串類   out   注意   ati   package   date()   

字串類為JAVA中的特殊類,String中為final類,一個字串的值不可重複。因此在JAVA VM(虛擬機器)中有一個字串池,專門用來儲存字串。如果遇到String a=”hello”時(注意沒有NEW,不是建立新串),系統在字串池中尋找是否有”hello”,此時字串池中沒有”hello”,那麼系統將此字串存到字串池中,然後將”hello”在字串池中的地址返回a。如果系統再遇到String b=”hello”,此時系統可以在字串池中找到 “hello”。則會把地址返回b,此時a與b為相同。

String a=”hello”;

System.out.println(a==”hello”);

系統的傳回值為true。

 

 1 package TomText; 2  3 public class TomText_36 { 4     private int day; 5     private int month; 6     private int year; 7     public TomText_36(int d,int m,int y){         8         day=d; 9         month=m;10         year=y;11     }12     public void setDate(int d,int m,int y){13         day=d;14         month=m;15         year=y;16     }17     public void printDate( ){18         System.out.println("今天是"+year+"年"+month+"月"+day+"日");19     }20     21     public static void main(String[] args){22         TomText_36 t=new TomText_36(3,4,2004);23         t.printDate();24         t.setDate(4, 5, 2018);25         t.printDate();26         27     }28 29 }

 

字串類為JAVA中的特殊類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.