50 java常用类_12 _System类

50 java常用类_12 _System类

  1. System系统类,主要用于获取系统的属性数据和其他操作,构造方法私有的。

    方法名说明
    static void arraycopy(…)复制数组
    static long currentTimeMillis();获取当前系统时间,返回的是毫秒值
    static void gc();建议JVM赶快启动垃圾回收器回收垃圾
    static void exit(int status);退出jvm,如果参数是0表示正常退出jvm,非0表示异常退出jvm。
    package com.wlw.common_class.system;
    
    import java.util.Arrays;
    
    public class demo01 {
        public static void main(String[] args) {
            //1 System.arraycopy():复制数组
            // src:源数组
            // srcPos:源数组开始位置
            // dest:目标数组
            // destPos:目标数组的位置
            // length:长度
            int[] array = {45,165,65,15,75,56,98,13};
            int[] dest = new int[8];
            System.arraycopy(array,4,dest,4,4);
    
            for (int i = 0; i < dest.length; i++) {
                System.out.println(dest[i]);
            }
    
            // Arrays.copyOf(); 这个方法里 也是调用的 System.arraycopy(),
    
            //2 System.currentTimeMillis() 获取当前系统时间,返回的是从 1970年1月1日00:00:00开始到现在的毫秒值
            //可以做一个计时器
            System.out.println(System.currentTimeMillis());
            long start = System.currentTimeMillis();
            for(int i = 0; i<= 99999999; i++){
                for (int j = 0; j <=99999999; j++ ){
                    i += j;
                }
            }
            long end = System.currentTimeMillis();
            System.out.println("时间:"+(end - start));
    
            //3.System.gc() ;垃圾回收
            //它在调用时,会调用finalize() 方法,这是Object类中的方法
            //可以到 39 java常用类_1 _Object类 中看
            System.gc();
    
            //4.System.exit();退出JVM
            System.exit(0);
            System.out.println("退出了"); //并不会执行
    
        }
    }
    
    /*
    执行结果:
    0
    0
    0
    0
    75
    56
    98
    13
    1594808996643
    时间:41
    
    */
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

悬浮海

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值