包装类
java 中的基本数据类型 不是面向对象语言。
包装类 是 八个基本数据类型对应的统称。。
作用
1.方便涉及到对象操作。
fianl 不能撇继承 是工具类。。
类 Integer
能在 int和String 之间转换 ,还提供了一些其它常量和方法。
1 。,把基本数据类型转换为包装类
1.构造方法
2.方法 valueOf
2.包装类转换为 int
int a = interger.intValue();
3 . 把String 类型转化成对应的包装类。
1.构造方法
String str =“123”;
Integer n =new Ineger(str);
2.fvalue 方法
4.把包装类转成 String
5.常用的方法
INTER,MAX_VALUE
6.字符串转基本数据类型
Integer.parseInt();//
nteger.parseint
现在 自动装箱和自动拆箱
Integer in3 = 123;
int num3 =in3;
面试题
String 类
字符串是常量,他们的值在创建后不能改变。字符串不可被改变
字符串接收
Stringbuffer 可变字符序列 buffer 缓冲区
Date
util Date
sql Date
Date date3 =new Date(98,7,8);
System.out.(date3.to\
Dare sqlDate = new java,sql,Date
new java,sql,Date(i);
把字符串传给Date
日期的格式化。
Calendar
做题套路
1.字符串转成Date
String temp = scanner.nextLine();
DateFormat format = new SimpleDateFormat("yyyy-MM-dd);
Date date = format.parse(temp);
2.Date 转成日历 Calendar
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);// 使用给定的 Date 设置此 Calendar 的时间
- 把1999-12-23修改为1999-12-1
cal.set(Calendar.DATE,1);
4.判断1999-12-1是星期几 cal.get(Calendar.DAY_OF_WEEK)
5.获取当前月的最大天数 cal.getActualMaximum(Calendar.DATE)
6.如何判断每天是不是星期六,如果是周六,换行- cal.get(Calendar.DAY_OF_WEEK)==7
- 7.判断是不是当天,如果是,打印
- cal.get(Calendar.DATE)