22System类
System类
方法
- arraycopy 数组的复制
- System.currentTimeMillis() 返回值也是1970年到现在 格林威治时间 1970-01-01 08:00:00.
- System.gc();回收垃圾
- System.exit(0);//0为正常退出 非0非正常退出 不出执行下面的输出了
package System;
public class demo01 {
public static void main(String[] args) {
//arraycopy 数组的复制
// 比array.copyof()效率高 因为后者的方法体用的是前者
int []a={1,10,2,20,23};
int []b=new int[5];
System.arraycopy(a,2,b,0,3);
//a 原数组 0 从原数组的那个位置开始复制
// b复制目标 0复制到b的那个位置 a.lebgth 复制多少个元素
for (int i = 0; i < a.length; i++) {
System.out.print(b[i]+" ");
if (i==(a.length-1)){
System.out.println(" ");
}
}
/* for (int i : b) {
System.out.print(i+" ");
if(i==b.length-1){
System.out.println("\t ");
}
}*/
System.out.println("=========2==========");
//System.currentTimeMillis() 返回值也是1970年到现在 格林威治时间 1970-01-01 08:00:00.
System.out.println( System.currentTimeMillis());//返回值也是1970年到现在 格林威治时间 1970-01-01 08:00:00.
long start=System.currentTimeMillis();
for (int i = 0; i < 999999; i++) {
for (int i1 = 0; i1 < 99999999; i1++) {
int result=i1+1;
}
}
long end=System.currentTimeMillis();
System.out.println("用时:"+(end-start));
System.out.println("=========3==========");
// System.gc();回收垃圾
new Student("aaa",23);
new Student("aa",83);
new Student("aag",213);
new Student("asda",3);
System.gc();
System.out.println("=========4==========");
//
System.exit(0);//0为正常退出 非0非正常退出 不出执行下面的输出了
System.out.println("结束");
}
}
2 20 23 0 0
=========2==========
1628521798467
用时:11
=========3==========
=========4==========
name: asda
age: 3已回收
name: aag
age: 213已回收
name: aa
age: 83已回收
name: aaa
age: 23已回收
Process finished with exit code 1212165