System类的使用

1.System类:

  不能被实例化,调用方式:  System.方法

 2.用于计算程序执行的时间,currentTimeMillis()方法

  System.currentTimeMillis();

public static void main(String[] args) {
//程序未运行的当前时间
                long t = System.currentTimeMillis();
        //System.out.println(t);
        for (int i = 0; i < 100000; i++) {
            System.out.println(i);
            
        }
//程序运行完的时间
        long end = System.currentTimeMillis();
//程序结束用的时间
        System.out.println(end-t);
}        

3.垃圾回收 ,gc();方法

Person:

public class Person {
//finalize最终的
     public void finalize(){
         System.out.println("垃圾收取了");
     }
}
TestPerson:
public static void main(String[] args) {
          fun();
}
public static void fun(){
              new Person();
              new Person();
              new Person();
              new Person();
             System.gc();
    }
原文地址:https://www.cnblogs.com/duguangming/p/10570582.html