Java常用类库---方法整理

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);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值