首页 > 其他分享 >System类

System类

时间:2023-02-17 10:58:21浏览次数:32  
标签:name int age System Student public

import javax.swing.plaf.synth.SynthLookAndFeel;

public class Demo01 {
public static void main(String[] args){
//1.arraycopy:数组复制
//src:源数组
//srcPos:从源数组哪个位置开始复制
//dest:目标数组
//destPos:从目标数组哪个位置开始放
//length:复制的长度
int[] array={1,2,3,4,5,6,7,8};
int[] dest = new int[8];
System.arraycopy(array,0,dest,0,4);
for (int i = 0; i <dest.length ; i++) {
System.out.print(dest[i]+"\t");//1 2 3 4 0 0 0 0
}

//2.System.currentTimeMillis();获取当前时间的毫秒数 作用:可计时
long start = System.currentTimeMillis();
for (int i = -999999999; i <999999999 ; i++) {
for (int j = -999999999; j <999999999 ; j++) {
int result = i + j;
}
}
long end =System.currentTimeMillis();
System.out.println("用时:"+(end-start));//用时:11(毫秒)

//3.System.gc();通知jvm回收垃圾
new Student("a",18);
new Student("b",19);
new Student("c",20);

System.gc();
/*
a回收了
c回收了
b回收了
*/

//4.System.exit(0);退出jvm
System.exit(0);
System.out.println("程序结束");//已经退出jvm,后面的不再执行
}

}


public class Student {
private String name;
private int age;

public Student() {

}

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(this.name+"回收了");
}
}

标签:name,int,age,System,Student,public
From: https://www.cnblogs.com/123456dh/p/17129343.html

相关文章