java-System类

1、System类的概述和方法使用
  * A:System类的概述
    * System 类包含一些有用的类字段和方法。它不能被实例化。
  * B:成员方法
    * public static void gc()
    * public static void exit(int status)
    * public static long currentTimeMillis()
    * pubiic static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)

例:

 1 public class Demo3_System {
 2 
 3     public static void main(String[] args) {
 4         //demo1();
 5         //demo2();
 6         //demo3();
 7         
 8         int[] src = {11,22,33,44,55};
 9         int[] dest = new int[8];
10         for (int i = 0; i < dest.length; i++) {
11             System.out.println(dest[i]);
12         }
13         
14         System.out.println("--------------------------");
15         System.arraycopy(src, 0, dest, 0, src.length);        //将数组内容拷贝
16         
17         for (int i = 0; i < dest.length; i++) {
18             System.out.println(dest[i]);
19         }
20     }
21 
22     public static void demo3() {
23         long start = System.currentTimeMillis();        //1秒等于1000毫秒
24         for(int i = 0; i < 1000; i++) {
25             System.out.println("*");
26         }
27         long end = System.currentTimeMillis();            //获取当前时间的毫秒值
28         
29         System.out.println(end - start);
30     }
31 
32     public static void demo2() {
33         System.exit(1);                            //非0状态是异常终止,退出jvm
34         System.out.println("11111111111");
35     }
36 
37     public static void demo1() {
38         for(int i = 0; i < 100; i++) {
39             new Demo();
40             System.gc();                        //运行垃圾回收器,相当于呼喊保洁阿姨
41         }
42     }
43 
44 }
45 
46 class Demo {                                    //在一个源文件中不允许定义两个用public修饰的类
47 
48     @Override
49     public void finalize() {
50         System.out.println("垃圾被清扫了");
51     }                            
52     
53 }
原文地址:https://www.cnblogs.com/hfumin/p/10194675.html