System 的功能是通用的,都是直接用类名调用即可,所以 System 不能被实例化。

    System 类的常用方法:

    • public static void exit(int status):终止当前运行的 Java 虚拟机,非零表示异常终止
    • public static long currentTimeMillis():返回当前系统的时间毫秒值形式
    • public static void arraycopy(数据源数组, 起始索引, 目的地数组, 起始索引, 拷贝个数):数组拷贝

    currentTimeMillis 执行时间

    1. // 返回 1970-1-1 00:00:00 走到此刻的总的毫秒值
    2. long time = System.currentTimeMillis();
    3. System.out.println(time);
    4. long startTime = System.currentTimeMillis();
    5. long sum = 1;
    6. // 进行时间的计算:性能分析
    7. for (int i = 0; i < 1000000; i++) {
    8. sum *= i;
    9. }
    10. System.out.println(sum);
    11. long endTime = System.currentTimeMillis();
    12. System.out.println((endTime - startTime) / 1000.0 + "s");
    int[] arr1 = {10, 20, 30, 40, 50, 60, 70};
    int[] arr2 = new int[6]; // [0, 0, 0, 0, 0, 0] ==>  [0, 0, 40, 50, 60, 0]
    System.arraycopy(arr1, 3, arr2, 2, 3);
    System.out.println(Arrays.toString(arr2));
    
    • 参数一:被拷贝的数组
    • 参数二:从哪个索引位置开始拷贝
    • 参数三:复制的目标数组
    • 参数四:粘贴位置
    • 参数五:拷贝元素的个数