java常用类之System类

java常用类之System类

  • System类系统类,主要用于获取系统的属性数据和其他操作,构造方法私有。
方法名说明
static void arrayCopy(…)复制数组
static long currentTimeMillis()获取当前的系统时间,返回的是毫秒值
static void gc()建议JVM赶快启动垃圾回收器回收垃圾
static void exit(int status);退出JVM,如果参数为0表示正常退出JVM,非0表示异常突出JVM

案例:

package hai.bok.strclass;

public class Test07 {
    public static void main(String[] args) {
        /**
         * arraycopy 实现数组的复制
         * src:源数组
         * srcPos;从那个位置开始复制
         * dest:目标数组
         * destPos:目标数组的位置
         * length:复制的长度
         */
        int[] arr={20,18,38,65,2,99,13,45};
        int[] dest=new int[8];
        //1.复制数组
        System.arraycopy(arr,0,dest,0,8);
        for (int i = 0; i < dest.length; i++) {
            System.out.println(dest[i]);
        }

        //2.获取毫秒数
        long star=System.currentTimeMillis();
        int result=0;
        for (int i = 0; i < 9999; i++) {
                result+=i;
        }
        long end=System.currentTimeMillis();
        System.out.println("用时:"+(end-star));

        //3.回收垃圾
        new Student("aaa",20);
        new Student("bbb",20);
        new Student("ccc",20);
        new Student("ddd",20);
        System.gc();//告诉垃圾回收器回收。

        //4.退出JVM
        System.exit(0);
        System.out.println("程序结束l");

    }
}

常用类学习告一段落啦。完结,撒花!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值