1. 程式人生 > >基礎資料型別包裝類

基礎資料型別包裝類

1、包裝類封裝了相應的基本資料型別數值。

2、基本資料型別4大類8小類對應的包裝類分別為

byte======Byte

short====== Short

int======Integer

long======Long

char====== Character

boolean======Boolean

float======Float

double======Double

3、Byte使用簡介

         Byte b2 = new Byte("12");//構造方法

         System.

out.println(b2.MAX_VALUE);//最大值

         System.out.println(b2.MIN_VALUE);//最小值

         System.out.println(b2.SIZE);//byte值的位數

         System.out.println(b2.BYTES);//byte值的位元組數

         System.

out.println(b2.toString());//返回一個String物件

         System.out.println(Byte.valueOf(b2));//Byte例項

         System.out.println(b2.doubleValue());//返回double物件

 

4Long 使用簡介

//構造方法

         Long

l1 = new Long("1112");

         Long l2 = new Long(1118);

        

         System.out.println(l1.byteValue());

         //結果0,表示x == y ; 結果小於0,表示如x < y ; 結果大於0,表示x > y

         System.out.println(Long.compare(l1, l2));

         System.out.println(l1.compareTo(l2));

        

         System.out.println(l2.doubleValue());

         System.out.println(l2.floatValue());

         //返回 Long作為int的值

         System.out.println(l1.intValue());

         //兩個 long的較大值

         System.out.println(Long.max(l1, l2));