Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
About Warpper Classes

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

l          Wrapper Classes(包裝類別)

l           特別注意常出現狀況

n          Wrapped values不能被更改。

n          不能直接把Boolean拿來evaluate true/false值,否則會compiler error

n          不同classwrapper class,即使值相同,用equals()去比也是false

n          primitve xxxValue()    //不接受任何引數,回傳primitive

n          primitive parseXXX(String)  //只接受String引數,回傳primitive

n          Wrapper valueOf(String)  //只接受String引數,回傳wrapper object

l           primitive data types / wrapper classes

primitive types

Wrapper classes

boolean

Boolean

byte

Byte

short

Short

int

Integer

long

Long

char

Character

float

Float

double

Double

l           Primitives產生String / String中剖析出Primitives

classes

primitive value轉成
string object

string object剖析成
primitive values

意義

直接將primitive value轉成string object

直接將string object剖析成primitive values

注意事項

n           static method

n           radix可是任意基底

n           static method

n           radix可是任意基底

n           throws NumberFormatException

n           return typeprimitive type

舉例

Integer.toBinaryString(15)  //1111

Integer.toOctalString(15)   //17

Integer.toHexString(15)    //f

Integer.toString(15,3)     //120

Integer.parseInt(“15”)       //15

Integer.parseInt(“15”,16)    //21

Integer.parseInt(“f”,16)      //15

Integer.parseInt(“1010”,2)  //10

Integer.parseInt(“0xf”,16)  //丟出NumberFormatException

Byte

String toString(type s)

ex : String toString(byte s)

//type為對應之primite type(byteshortbooleancharfloatdouble)

long parseByte(String s)

long parseByte(String s,int radix)

Short

long parseShort(String s)

long parseShort(String s,int radix)

Float

float parseFloat(String s)

Double

double parseDouble(String s)

Boolean

 

Character

 

Integer

String toBinaryString(type i)

String toHexString(type i)

String toOctalString(type i)

String toString (type i)

String toString(type i,int radix)

// type為對應之primite type(intlong)

int parseInt(String s)

int parseInt(String s,int radix)

Long

long parseLong(String s)

long parseLong(String s,int radix)

l           Primitive產生Wrapped objects / 取出Wrapped Objects內的Wrapped Value

classes

Primitive產生

Wrapped objects

取出Wrapped Objects內的

Wrapped Value

意義

primitive value包裝成wrapped object

取出wrapped objects內的wrapped value

注意事項

 

n           instance method

舉例

Integer wi = new Integer(15);

Boolean wb = new Boolean(true);

Integer wi = new Integer(15);

println(wi.doubleValue()); //15.0

Boolean

Type(type val)

ex : Boolean(boolean val)

// Type為對應之Wrapped Object

(BooleanCharacter...)

// type為對應之primite type

(booleanchar...)

boolean booleanValue()

Character

char charValue()

Short

byte byteValue()

short shortValue()

ing intValue()

long longValue()

float floatValue()

double doubleValue()

Integer

Long

Byte

Float

Double

l           String產生Wrapped Object

classes

method

意義

將對應的primitive value包裝成wrapped object

注意事項

n           constructorsstatic methods

n           static methodsreturn typewrapper class而非primitive type

n           都會throws NumberFormatException

n           string的開頭是”0X””0x””#”,則以16為基底來parse(開頭08為基底),否則以10為基底來parse

n           radix可是任意基底。

valueOf(String s)

10為基底來parse string ”s”

decode(String s)

先看”s”字串的開頭為何再決定以16108為基底來parse

舉例

Integer.decode(“15”).byteValue()    //15

Integer.decode(“030”).shortValue()  //24

Integer.decode(“0x0f”).intValue()    //15

Integer.valueOf(“100”).byteValue()  //100

Integer.valueOf(“2w”).byteValue()   //throws NumberFormatException

Integer.valueOf(“f”,16).byteValue()  //15

Integer.valueOf(“20”,3).byteValue()  //6

Character

 

Boolean

Type(String s)  // constructor

static Type valueOf(String)

// Type為對應之Wrapped Object(BooleanFloatDouble)

Float

Double

Short

Type(String s)  // constructor

static Type decode(String s)

static Type valueOf(String s)

static Type valueOf(String s,int radix)

// Type為對應之Wrapped Object(ShortIntegerLongByte)

Integer

Long

Byte

l           Character內常用的Class Methods

用途

改變或判斷char value

舉例

Character.isLetter(‘a’); // true

Character.isDigit(‘5’); // true

Character.toLowerCase(‘Q’); // q

methods

static boolean isDigit(char ch)

static boolean isLetter(char ch)

static boolean isLetterOrDigit(char ch)

static boolean isLowerCase(char ch)

static boolean isUpperCase(char ch)

static boolean isWhiteSpace(char ch)

static char toLowerCase(char ch)

static char toUpperCase(char ch)


来自于:【 Garfield 的 SCJP 閱讀筆記 】


相关文章

相关软件