System类

System常见的方法和案例解析

  1. 退出当前程序EXIT,0表示正常状态退出
  2. 获取当前的时间
  3. 拷贝,数组拷贝底层用此代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package Learn;

import java.util.Arrays;

public class Test {
public static void main(String[] args) {
/**
*
src – the source array.原数组
srcPos – starting position in the source array.在原数组的开始位置
dest – the destination array.目标数组
destPos – starting position in the destination data.在目标数组的开始位置
length – the number of array elements to be copied从原数组拷贝多少个数
*/
int a[] = {1, 2};
int b[] = new int[10];
System.arraycopy(b, 0, a, 0, 2);
System.out.println(Arrays.toString(b));
//获取当前时间到1970.1.1的时间,毫秒为单位
//the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
long time=System.currentTimeMillis();
System.out.println(time);
System.exit(0);
}
}


image-20220302160950870