java基礎-基礎類型封裝類型

來源:互聯網
上載者:User

標籤:rac   字串   自動裝箱   java   public   bsp   操作   拆箱   ati   

想要對基本類型資料進行更多的操作,最方便的方式就是將其封裝成對象。為啥呢?因為在對象描述中就可以定義更多的屬性和行為對該基礎資料型別 (Elementary Data Type)進行操作。【八種基礎資料型別 (Elementary Data Type)的封裝類】byte ——Byteshort ——Shortint ——Integerlong-----Longfloat-----Floatdouble----Double char----Characterboolean---Boolean基礎資料型別 (Elementary Data Type)變成對象封裝類的好處】1 可以將基本資料和字串之間進行互相的轉換。 public static void main(String[] args) { Integer index = 12;//基礎類型封裝類型Integer String str_index = index.toString();//封裝類型Integer轉換為字串 index = Integer.parseInt(str_index);//字串轉為封裝類型Integer }2 包含每種基礎資料型別 (Elementary Data Type)的相關屬性如最大值、最小值等,以及相關的操作方法。 public static void main(String[] args) { Integer max = Integer.MAX_VALUE;//int最大值 Integer min = Integer.MIN_VALUE;//int最小值 }3 基本類型與封裝類型自由轉換.也可以稱為自動拆箱與自動裝箱 public static void main(String[] args) { Integer index = 100; int _index = index;//自動拆箱 index = _index;//自動裝箱 }

 

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.