system类

来源:互联网 发布:男士衣服搭配 知乎 编辑:程序博客网 时间:2024/06/10 11:10
ic static void main(String[] args) {
        /** 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)
        * C:案例演示
        * System类的成员方法使用*/
        //demo1();
        //demo2();
        //demo3();
        int [] src ={11,22,33,44,55};
        int [] dest =new int [8];
        System.arraycopy(src, 0, dest, 0, src.length);
        for (int i = 0; i < dest.length; i++) {
            System.out.println(dest[i]);//拷贝数组数据
            
        }
        
        
        
    }

    public static void demo3() {
        long start =System.currentTimeMillis();
        for (int i = 0; i < 1000; i++) {
            System.out.println("*");
            
        }
        long end =System.currentTimeMillis();//计算程序运行时间以毫秒为单位
        System.out.println(end-start);
    }

    public static void demo2() {
        System.exit(0);
        System.out.println("111111111");//推出java虚拟机
    }

    public static void demo1() {
        for (int i = 0; i < 100; i++) {
            new Demo();
            System.gc();//运行垃圾回收机制  叫保洁阿姨
            
        }
    }

}
class Demo{  //在一个源文件中不允许定义两个public类
    public  void finalize(){
        System.out.println("垃圾被清扫了");
        
    }
   

原创粉丝点击