System 的功能是通用的,都是直接用类名调用即可,所以 System 不能被实例化。
System 类的常用方法:
public static void exit(int status):终止当前运行的 Java 虚拟机,非零表示异常终止public static long currentTimeMillis():返回当前系统的时间毫秒值形式public static void arraycopy(数据源数组, 起始索引, 目的地数组, 起始索引, 拷贝个数):数组拷贝
currentTimeMillis 执行时间
// 返回 1970-1-1 00:00:00 走到此刻的总的毫秒值long time = System.currentTimeMillis();System.out.println(time);long startTime = System.currentTimeMillis();long sum = 1;// 进行时间的计算:性能分析for (int i = 0; i < 1000000; i++) {sum *= i;}System.out.println(sum);long endTime = System.currentTimeMillis();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));
- 参数一:被拷贝的数组
- 参数二:从哪个索引位置开始拷贝
- 参数三:复制的目标数组
- 参数四:粘贴位置
- 参数五:拷贝元素的个数
