zoukankan      html  css  js  c++  java
  • System类

    System类概述

    System类不能手动创建对象,因为构造方法被private修饰,阻止外界创建对象。System类中的都是static方法,类名访问即可。在JDK中,有许多这样的类。

    成员方法

    public static void gc() 运行垃圾回收机制
    public static void exit(int status) 终止正在运行的java虚拟机
    public static long currentTimeMillis() 返回以毫秒为单位的当前时间
    public static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length) 从指定源数组中复制一个数组,复制从指定的位置开始,到目标数组的指定位置结束。其中src为源数组,srcPos为源数组的起始位置,dest为目标数组,destPos为目标数组中的起始位置,length为要复制数组元素的数量。

    public class test {
        public static void main(String[] args) {
            for(int i=0;i<4;i++){
                new Demo();
                System.gc();     //运行垃圾回收机制
            }
        }
        
    }
    class Demo{
        public void finalize(){
            System.out.println("垃圾被清扫了。");
        }
    }

    public class test {
        public static void main(String[] args) {
            System.exit(1);   //非0状态是异常终止,退出jvm
            System.out.println("111111111");
        
        }
        
    }
    没有输出

    public class test {
        public static void main(String[] args) {
            long start=System.currentTimeMillis();
            for(int i=0;i<100;i++){
                System.out.print("*");
            }
            long end=System.currentTimeMillis();
            System.out.println();
            System.out.println(end-start);
        
        }
        
    }
    输出:
    ****************************************************************************************************
    2

    public class test {
        public static void main(String[] args) {
            int[] src={11,22,33,44,55};
            int[] dest=new int[10];
            for(int i=0;i<dest.length;i++){
                System.out.print(dest[i]);
                System.out.print(" ");
            }
            System.out.println();
            System.out.println("----------------------");
            System.arraycopy(src, 0, dest, 0, src.length);
            for(int i=0;i<dest.length;i++){
                System.out.print(dest[i]);
                System.out.print(" ");
            }
                
        }
    输出:
    0 0 0 0 0 0 0 0 0 0 
    ----------------------
    11 22 33 44 55 0 0 0 0 0 
  • 相关阅读:
    【C/C++】Dijkstra算法的简洁实现
    【数学建模】图论方法的数学模型
    【数学建模】模糊数学模型详解
    【数学建模】基于问题的线性规划和混合整数规划求解
    【机器学习】非常全的机器学习资源汇总
    【数据结构】数据结构中的各种树详解
    【数据结构】八大排序算法
    【数据结构】七大查找算法
    【数学建模】MATLAB语法
    【论文阅读】Sequence to Sequence Learning with Neural Network
  • 原文地址:https://www.cnblogs.com/qq1312583369/p/11112371.html
Copyright © 2011-2022 走看看