常用类

  • BigDelimal 类

作用:精确运算浮点小数
创建:BigDelimal bd = new BigDelimal(“1.0”);//给它字符串数据

BigDecimal bd1 = new BigDecimal("99.0");
BigDecimal bd2 = new BigDecimal("10.9");
BigDecimal sBigDecimal = bd1.subtract(bd2);
System.out.println(sBigDecimal);     输出:88.1
//subract();减法
//add();加法
//divide();除法
//multiply();乘法
---------------------------------------------
除法除不尽怎么办:    使用:BigDecimal.ROUND_HALF_UP 四舍五入
BigDecimal bd3 = bd1.divide(divisor, scale, roundingMode)
scale()保留几位小数
----------------------------------------------------
roundingMode:输入设定参数比如BigDecimal.ROUND_HALF_UP
----------------------------------------------------
BigDecimal bd3 = bd1.divide(bd2, 3, BigDecimal.ROUND_HALF_UP);
System.out.println(bd3);
  • Date 类 : 输出当前时间

date类下面的几种方法:

方法名说明
after()在当前时间之后
before()在当前时间之前
comparTo()比较时间的毫秒值
equals()比较是否相等
创建Date对象  输出今天的时间
        //今天  
		Date oDate1 = new Date();
		System.out.println(oDate1);
		System.out.println(oDate1.toLocaleString());//用的是已过时方法输出现在的时间
		//输出:Mon Dec 21 15:19:29 CST 2020
                 2020-12-21 15:19:29
		//昨天
		Date oDate2 = new Date(oDate1.getTime()-(60*60*24*1000));//今天的时间减去一天的毫秒数
		System.out.println(oDate2);//输出Sun Dec 20 15:19:29 CST 2020
		System.out.println(oDate2.toLocaleString());//输出2020-12-20 15:19:29
		//方法 after();在当前时间之后
		boolean b1 =oDate1.after(oDate2);
		System.out.println(b1);//输出true
		//方法 before();在当前时间之前
		boolean b2 =oDate1.before(oDate2);
		System.out.println(b2);//输出false
		//comparTo();比较毫秒值   输出 1,0,-1
		int b3 = oDate1.compareTo(oDate2);
		System.out.println(b3);//输出:1
		//equals比较时间是否相等
		boolean b4 = oDate1.equals(oDate2);
		System.out.println(b4);//输出false
  • Calendar 类

  • SimpleDateFormat 类

  • System 类

    System类代表系统,系统级的很多属性和控制方法都放置在该类的内部。该类位于java.lang包。由于该类的构造方法是private的,所以无法创建该类的对象,也就是无法实例化该类。其内部的成员变量和成员方法都是static的,所以也可以很方便的进行调用。

    1. ###  arraycopy();数组的复制
   		例:System.arraycopy(src, srcpos, dest, destpos, length);
   		src(源数组) 
   		srcpos(从那个位置开始复制)
   		dest(目标数组)
   		destpos(目标数组的位置)
   		length(复制的长度)
   		----------------------以下实例-------------------------
   		public class Calendar1 {
		public static void main(String[] args) {
			int[] arr={23,43,64,57,3,23,46,7,43,24};
			int[] dest=new int[10];
			System.arraycopy(arr, 1, dest, 0, arr.length-1);
			System.out.print(Arrays.toString(dest));//输出1
			System.out.println();
			for(int i=0;i<dest.length;i++){
				System.out.print(dest[i]+"  ");//输出2
			}
		}
}
输出结果:
[43, 64, 57, 3, 23, 46, 7, 43, 24, 0]---输出1
43  64  57  3  23  46  7  43  24  0  ---输出2
----------------------------------------------------------------
	2.###  currentTimeMillis();获取毫秒数
	---------------计算程序运行时间----------------
	long end = System.currentTimeMillis();
			for(int i = -999999;i<99999999;i++){
				for(int j = -999999;j<9999999;j++){
					int start=i+j;
				}
			}
			long end1 = System.currentTimeMillis();
			System.out.println("用时:"+(end1-end));
输出结果:
       用时:6;
---------------------------------------------------------------
	3.###  System.gc();告诉垃圾回收站回收垃圾
	随便建一个类:
	public class s {
	int i;
	int p;
      @Override
	public String toString() {
		return "s [i=" + i + ", p=" + p + "]";
	}
       s(){}//构造方法
       s(int i,int p){
    	   this.i = i;
    	   this.p = p;
       }
       protected void finalize()throws Throwable{ 	
    	   System.out.println("回收了:"+i+"  "+p);
	}
}
----------------------接着-----------------
			new s(1, 3);
			new s(8, 8);
			System.gc();//使用这个方法
输出如下:回收了:8  8      回收了:1  3
------------------------------------------------------
	4.###  System.exit(0);//退出jvm
	
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值