System类
- exit(0)退出当前程序
arrarycopy:复制数组元素,比较适合底层调用,一般使用Arrary.copyOf完成复制数组
int[] src={1,2,3}; int[] dest = new int[3]; System.arraycopy(src,0,dest,0,3);
- currentTimeMillens:返回当前时间距离的毫秒数
- gc:运行垃圾回收机制
System.gc()
垃圾回收实例——学生类
public class Student {
private String name;
private int age;
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
protected void finalize() throws Throwable {
System.out.println("回收了"+name+" "+age);
}
}
垃圾回收——测试类
public class Test01 {
public static void main(String[] args) {
new Student("小明",20);
new Student("小红",28);
new Student("小刚",22);
System.gc();
}
}