package com.qf.demo2;
/**
* 常用類
*
* 不完全面向?qū)ο? 基本數(shù)據(jù)類型
* 八種 不能創(chuàng)建對象 沒有 方法和屬性
*
*
* 裝箱和拆箱
* 把基本數(shù)據(jù)類型數(shù)據(jù)放到 箱子里 過程叫做裝箱
* 把基本數(shù)據(jù)類型數(shù)據(jù)從箱子里面拿出來的過程叫做拆箱
*
* 8個類
* 包裝類
* Integer int 在一個箱子里面 給 每一個基本數(shù)據(jù)類型增加了功能
* Byte byte
* Short short
* Long long
* Float float
* Double double
* Boolean boolean
* Character char
*
*
* String
*
* Date 日期
* Calendar 日歷
* SimpleDateFormat
*
*
* System
* Runtime
*
*
*
* 裝箱 構(gòu)造方法
* valueOf
*
* 拆箱 XXXValue
*
*
* parseXXX 將 字符串轉(zhuǎn)成 XXX 基本數(shù)據(jù)類型
* (字符串只能包含數(shù)字)
*
*/
public class Test {
public static void main(String[] args) {
int i = 6;
System.out.println(Integer.MAX_VALUE);
System.out.println(Integer.MIN_VALUE);
System.out.println(Long.MAX_VALUE);
//Integer.hashCode(value)
// 將 數(shù)字放到integer對象中 裝箱
Integer integer = new Integer(67);
System.out.println(integer);// 重寫了 toString方法 打印的是內(nèi)容
Integer integer2 = new Integer("123");// 字符串中只包含數(shù)字 才不會包 NumberFormatException(數(shù)字格式化異常)
System.out.println(integer2);
byte b = integer.byteValue();
System.out.println(b);
short s = integer.shortValue();
System.out.println(s);
// 將基本數(shù)據(jù)類型 數(shù)據(jù) 從箱子里面 拆出來
int i2 = integer.intValue();
System.out.println(i2);
integer.longValue();
integer.floatValue();
integer.doubleValue();
/**
* 拆箱
* XXXValue()
*
*/
//比較大小 負(fù)數(shù) 0 正數(shù)
// 兩個參數(shù) 相同的情況下 0
// 4 5 負(fù)數(shù) 第一個參數(shù)比第二個參數(shù)小 返回負(fù)數(shù)
// 第一個參數(shù)比第二個參數(shù) 大 返回正數(shù)
int a= Integer.compare(5, 4);
System.out.println(a);
Integer i3 = new Integer(5);
Integer i4 = new Integer(5);
/**
* 調(diào)用者 和參數(shù)相比 比參數(shù)大 返回正數(shù)
* 調(diào)用者 比參數(shù)小 返回負(fù)數(shù)
* 調(diào)用者 和參數(shù)相同 返回 0
*/
int num = i3.compareTo(i4);
System.out.println(num);
System.out.println(i3.equals(i4));
// 將字符串 解析成 int 數(shù)字 十進(jìn)制 (字符串中只能包含數(shù)字)
int w= Integer.parseInt("345");
System.out.println(w);
System.out.println(Integer.toBinaryString(4));// 將十進(jìn)制轉(zhuǎn)成二進(jìn)制
System.out.println(Integer.toHexString(16));// 將十進(jìn)制轉(zhuǎn)成 十六進(jìn)制
System.out.println(Integer.toOctalString(9));// 將十進(jìn)制轉(zhuǎn)成八進(jìn)制
System.out.println(i3.toString());// 將Integer對象轉(zhuǎn)成 字符串
System.out.println(Integer.toString(9));//將 數(shù)字轉(zhuǎn)成 字符串
Integer integer3 = Integer.valueOf(6);
System.out.println(integer3);
}
}
注意:
// jdk1.5 以后 自動裝箱 自動拆箱
Integer integer = 12; // 隱含了裝箱
System.out.println(integer);
int w = 5+3+integer;// 隱含了一個拆箱 數(shù)字
System.out.println(w);