System系统类,主要用于获取系统的属性数据和其他方法,构造方法私有的
方法名 | 说明 |
---|---|
static void arraycopy(); | 复制数组 |
static long currentTimeMillis(); | 获取当前系统时间,返回的是毫秒值 |
static void gc(); | 建议jvm赶快启动垃圾回收器回收垃圾 |
static void exit(int status); | 退出jvm,如果参数是0表示正常退出,非0表示异常退出 |
package cylxt; public class Demo01 { public static void main(String[] args) { //1.arraycopy:数组的复制 int[] arr = {20,18,15,8,35,26,45,90}; int[] dest = new int[8]; //源数组arr,从哪个位置开始复制0,目标数组dest,目标数组的位置0,复制的长度arr.length System.arraycopy(arr,0,dest,0,arr.length); for (int i = 0; i < dest.length; i++) { System.out.println(dest[i]); } //2.获取毫秒数 System.out.println(System.currentTimeMillis()); long start = System.currentTimeMillis(); for (int i1 = 0; i1 < 99999999; i1++) { for (int i2 = 0; i2 < -99999999; i2++) { int result = i1+i2; } } long end = System.currentTimeMillis(); System.out.println("用时:"+(end-start)); //3.System.gc();告诉垃圾回收器回收 Student s1 = new Student("aaa",19); new Student("bbb",19); new Student("ccc",19); System.gc(); //4.退出jvm System.out.println("程序结束了"); System.exit(0);//后面的代码不会执行 System.out.println("程序结束了"); } }
package cylxt; public class Student { private String name; private int age; public Student(String name, int age) { super(); 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; } public Student(){ } @Override public String toString() { return "Student{" + "name='" + name + '\'' + ", age=" + age + '}'; } @Override protected void finalize() throws Throwable { System.out.println("回收了"+name+""+" "+age); } }
搜索
复制
标签:常用,name,int,age,System,Student,public From: https://www.cnblogs.com/sususyq-/p/16620940.html