1、包装类
基本数据类型对应的包装类,可以调用方法
byte–Byte
short–Short
int–Integer
long–Long
float–Float
double–Double
char–Character
boolean–Boolean
Integer构造方法
①Integer(int value)
② Integer(String s)例如:Integer n = Integer(“8”);n的值就是8;整型
Integer包装类常用方法
byteValue:将Integer转换成byte类型
doubleValue()
floatValue()
intValue()
longValue()
parseInt(String s):将字符串类型转换成int型
toString()
valueOf(String s):将字符串转换成Integer类型
2、基本类型和包装类之间的转换(拆箱和装箱)
int a = 10;
Integer a1 = new Integer(a);//手动装箱
Integer a2 = a;//自动装箱
Integer b = new Integer(10);
int b1 = b.intValue();//手动拆箱
int b2 = b;//自动拆箱
3、基本类型和字符串之间的转换
基本类型—>字符串
int c = 10;
String str = Integer.toString(c);或者
String str = String.valueOf(c);或者
String str = c +“”;
字符串—>基String str = “8”;
int a = Integer.valueOf(str);或者
int a = Integer.parseInt(str);ate类和SimpleDateFormat
(1)直接输出当Date day = new Date();
System.out.println(day);使用format()将日期转换为指定格式的文本输出
Date day = new Date();
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
String today = sdf.format(day);
System.out.println(today);
(3)用parse()方法将文本转换成日期
String day = “2017年05月02日 09:37:22”;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date today = sdf.parse(day);
System.out.println(today);
//注意格式中大小写区分
4、Calendar类java.util.Calendar:抽象方法
(1)获取年月日等信息
Calendar c = Calendar.getInstance();//创建Calendar对象
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
int second = c.get(Calendar.SECOND);
System.out.println("当前时间"+year+"-"+month+"-"+day+""+hour+":"+minute+":"+second);
Date date = c.getTime();//getTime()方法获取 Date对象完成 //Calendar和Date的转换
Long time = c.getTimeInMillis();//获取当前毫秒数
System.out.println("当前时间"+date);//结果Date格式时间
5、Math类中的静态方法
long round() :返回四舍五入后的整数
double floor():返回小于参数的最大整数
double ceil():返回大于参数的最小整数
double random():返回[0,1)之间的随机浮点数