1.Objects
isNull ( Object b )、nonNull(……)
返回 true如果提供的参考是 null ,否则返回 false 。
2.Math
abs(double b)返回绝对值
exp (double a) 返回e的指数值
min( , ) max( , ) 返回大者或小者
3.Arrays
binarySearch ( int[ ] a , int key ) 二分搜索指定值 返回下标(int)
binarySearch ( int[ ] a , int fromIdex , toIndex , int key ) 指定范围二分搜索
copyOf ( char original , int newLength) 使用0来拷贝 ,指定拷贝长度,返回 int [ ]
copyOfRange( char original , int from , int to )
equals ( int[ ] a , int[ ] n) 数组比较
equals ( int[ ] a , int aFrom , int aTo, int[ ] b, int bFrom , int bTo) 指定范围比较
sort ( int[ ] a ) 对数组升序排列, 可指定下标范围
toString(int[ ] a) 返回数组的字符串形式 用于打印
4.BigDecimal
用来解决小数运算的误差
用法实例
BigDecimal b1 = new BigDecimal ( 0.1 );
BigDecimal b2 = new BigDecimal ( 0.2 );
BingDecimal b3 = b1.add( b2 )
double b = b3.doubleValue();
4.Date
getTime() 返回自此 Date对象表示的1970年1月1日00:00:00 GMT以来的毫秒数。 ( long 型)
Date() 构造方法 不传参, 当前时间
5.DateFormat
用于格式化日期的类
使用SimpleDateFormat类创建对象
SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd HH:mm ss");
y : 年 M : 月 d : 日 H : 时 m : 分 s : 秒
String text = d.format(new Date()); //用format方法将Date对象转换成指定格式的字符串
Date date = d.parse("2021-12-12 12:12 12"); parse方法可将指定格式的字符串转成Date
6.Calendar
Calendar 是抽像类,用其提供的方法创建对象getInstance()
Calendar c1 = Calendar.getInstance();
//获取当前的年月日, 是一年的第几天、第几周等 int year = c1.get(Calendar.YEAR);
int day = c1.get(Calendar.DAY_OF_YEAR);
//设置时间 set c1.set(Calendar.YEAR,2021);
//时间运算 add c1.add(Calendar.YEAR,10);
//getTime(): 返回 日历时间表示的Date对象 Date d = c1.getTime();
//getActualMaxmum 该对象所在月份、年份的最大天数、月数 int m = c1.getActualMaximum(Calendar.DAY_OF_MONTH); System.out.println(m);