Day15_System类

System类

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


import java.util.Arrays;

public class Demo02 {
    public static void main(String[] args) {
        //arraycopy:数组的的复制
        //src:需要复制的数组/源数组
        //srcPos:从哪个位置开始复制
        //dest:目标数组
        //dePos目标数组的位置
        //length:复制的长度
        int[] arr={12,23,43,23,45,123,54,23,1,5};
        int[] dest=new int[10];
        /** public static native void arraycopy(Object src,  int  srcPos,
         *                                         Object dest, int destPos,
         *                                         int length);
         */
        System.arraycopy (arr,4,dest,7,3);
        for (int i = 0; i < dest.length; i++) {
            System.out.println (dest[i]);
        }
        //Arrays.copyOf (,);
        System.out.println (System.currentTimeMillis ());//从1970至当前的毫秒数,可用于程序计时
        long start= System.currentTimeMillis ();
        for (int i = -999999999; i <99999999 ; i++) {
            for (int j = -99999; j < 999999; j++) {
                int s=i+j;
            }
        }
        long end=System.currentTimeMillis ();
        System.out.println (end-start);

        Studnt s1=new Studnt ("aaa",10);
        new Studnt ("aa",10);
        new Studnt ("a",10);
        System.gc ();//告诉垃圾回收器回收

        //4.退出JVM
        System.exit (0);
        System.out.println ("哈哈");
    }
}

//运行结果

0
0
0
0
0
0
0
45
123
54
1606786591189
9
回收了a    10
回收了aa    10

Process finished with exit code 0
posted @ 2020-12-01 09:38  柠檬情  阅读(56)  评论(0编辑  收藏  举报