Integer类
java.lang包下,为8种基本数据类型提供了对应的包装类。包装类提供了字符串、基本数据类型、包装类之间的相互转换的方法数字基本数据类型的包装类都继承了Number类,它们的使用方式相似下面以常用的基本数据类型int对象的包装类Integer为例,说明数字类型包装类的使用
示例
package SE01
.n4Integer
;
public class Demo01Integer {
public static void main(String
[] args
) {
int i
=20;
Integer i1
=new Integer(i
);
Integer i2
=Integer
.valueOf(i
);
Integer in
=new Integer(20);
int in1
=in
;
System
.out
.println(in1
);
String s
="120";
Integer int1
=new Integer(s
);
Integer int2
=Integer
.valueOf(s
);
Integer int0
=new Integer(30);
String s1
=int0
.toString();
int a
=Integer
.parseInt(s
);
int b
=40;
String str
=String
.valueOf(b
);
String str2
=Integer
.toString(b
);
int aa
=new Integer(1);
Integer integer
=aa
;
Integer i10
=new Integer(10);
Integer i20
=new Integer(20);
Integer i30
=new Integer(10);
boolean b12
=i10
.equals(i20
);
boolean b13
=i10
.equals(i30
);
boolean b23
=i20
.equals(i30
);
System
.out
.println(b12
);
System
.out
.println(b13
);
System
.out
.println(b23
);
}
}
Boolean类
package SE01
.n4Wrapper
;
public class Demo01Boolean {
public static void main(String
[] args
) {
Boolean b1
=new Boolean(true);
Boolean b2
=Boolean
.valueOf(true);
Boolean b3
=new Boolean(true);
boolean b4
=b3
.booleanValue();
String s
="true";
Boolean bo1
=new Boolean(s
);
Boolean bo2
=Boolean
.valueOf(s
);
Boolean bo3
=new Boolean(true);
String s1
=bo3
.toString();
String s2
=Boolean
.toString(bo3
);
String s3
=String
.valueOf(bo3
);
boolean b
=true;
String str
=String
.valueOf(b
);
String str11
="true";
boolean bool1
=Boolean
.parseBoolean(str
);
Boolean bool2
=new Boolean(str11
);
boolean bool3
=bool2
.booleanValue();
}
}
Character类
类中的特有方法: 1.判断一个字符是否为字母或阿拉伯数字 isLetter(‘A’); isDigit(‘9’); 2.判断是否为空格 isWhitespace(’ '); 3.判断是否为大写或小写 isLowerCase(‘A’) isUpperCase(‘A’) 4.返回只含该字符的字符串 toString(‘A’) 5.转换为大写或小写 toUpperCase(‘a’) toLowerCase(‘A’)
package SE01
.n4Wrapper
;
public class Demo02Character {
public static void main(String
[] args
) {
Character c1
=new Character('A');
Character c2
=Character
.valueOf('A');
Character c3
=new Character('A');
char c4
=c3
.charValue();
char c5
=Character
.valueOf(c3
);
char c6
=Character
.toString(c3
).charAt(0);
System
.out
.println(Character
.isLetter('A'));
System
.out
.println(Character
.isDigit('9'));
System
.out
.println(Character
.isWhitespace(' '));
System
.out
.println(Character
.isLowerCase('A'));
System
.out
.println(Character
.isUpperCase('A'));
System
.out
.println(Character
.toString('A'));
System
.out
.println(Character
.toUpperCase('a'));
System
.out
.println(Character
.toLowerCase('A'));
}
}