System类
System类,主要获取系统的属性数据和其他操作,构造方法私有
方法名 | 说明 |
---|---|
arraycopy() | 复制数组 |
currentTimeMillis(); | 获取当前系统值,返回ms值 |
gc(); | 建议JVM启动垃圾回收器回收垃圾 |
exit(); | 退出JVM,如果参数为0表示正常退出,非0表异常退出 |
public static void main(String[] args) {
//1.arraycopy:数组的复制
//src,原数组
//srcPos:从哪个位置开始复制0
//dest;目标数组
//destPos:目标数组的位置
//length:复制的长度
int[] arr = {20,18,15,8,1,35,6,11,21};
int[] dest = new int[9];
System.arraycopy(arr,4,dest,4,4);
System.out.println(Arrays.toString(dest));
for (int i:dest) {
System.out.println(i);
}
//Arrays.copyof是使用System.arraycopy
//2.currentTimeMillis获取时间,ms值
System.out.println(System.currentTimeMillis());
long start = System.currentTimeMillis();
for (int i = 0; i < 99999; i++) {
for (int j = 0; j < 99999; j++) {
int result = i+j;
}
}
long end = System.currentTimeMillis();
System.out.println((end-start)+"ms");
//3.System.gc();告诉垃圾回收器回收
new Student("A",10);
new Student("B",11);
new Student("C",12);
System.gc();
//4.退出JVM
System.exit(0);
System.out.println("over");
}