为什么需要学习包装类?
1,如何判断一个字符是大写,小写 还是数字字符?
c >= 'a' &
& c <= 'z'
该判断是与字符相关,应该放在字符类里面 Character char
2,如何计算65的二进制,八进制,十六进制呢?
该计算与整数有关,应该放在整数类里面 Integer Byte Short Long
有了包装类,我们可以访问和数据类型相关的对象更多的方法
基本数据类型是没有什么方法可以调用的
任何数据类型都有一个class属性,他返回的是类文件
什么是包装类?
八大基本数据类型都对应值一个包装类类型
byte short int long float double char boolean
Byte Short Integer Long Float Double Character Boolean
掌握Integer 和 Character 其他的一模一样
Integer 是java.lang.Number 包下面的
任何Number类下的子类都可以转换成其他的数据类型,但是可能会出现精度丢失
static int BYTES
用于表示二进制补码二进制形式的 int 值的字节数
static int MAX_VALUE
一个持有最大值一个int可以有 2 31 -1
static int MIN_VALUE
的常量保持的最小值的int可以具有 -2 31
static int SIZE
用于表示二进制补码二进制形式的int值的位数
static 类<Integer> TYPE
类原始类型int 的类实例
Integer(int value)
构造一个新分配的 Integer对象,该对象表示指定的 int 值
Integer (String s)
构造一个新分配 Integer对象,表示 int 由指示值String参数
NumberFormatException
异常名称; 数字格式化异常
产生原因;字符串未满足数字的格式
integer的成员方法
public int Value() 拆箱 将Integer转化为整型
public static int parseInt(string s) 将字符串类型转换为int类型
public static String toString(int i) 将整型转换为字符串
public static Integer valueOf (int i) 将整型转换为Integer类型
public static Integer valueOf ( string s) 将整型转换为Integer类型
实现String和int之间的相互转换
int -- String
方式1 ;
int i = 100;
String s = i + " ";
方式2; 推荐
String s2 = String.valueof ( i );
方式3; String s3 = Integer.valueOf( i ) .toString( );
String -- int
方式1; 推荐
String num = " 100 "
int i1 = Integer.parseInt( num );
方式2;
int i2 = new Integer(num).intValue( );
方式3;
int i3 = Integer.valueOf( num ).intValue( );
进制转换
十进制转到其他进制: public static String toString(int i , int radix)
其他进制到十进制: public static int parseInt(int i ,int radix)
Math类概述,方法
Math.abs (double a) 求绝对值
Math.sqrt ( double a ) 开根号
Math.ceil ( double a ) 向上取整
Math.floor (double a ) 向下取整
Math.max (int a , int b ) 求最大值
Math.min (int a , int b ) 求最小值
Math.pow (double a , double b ) 求a的b次幂
Math.random (random) 生成随机数
Math.round (float a) 四舍五入