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 
  • 相关阅读:
    vscode入门使用教程(页面调试)
    .net core3.1开始页面实时编译
    Ubuntu 编辑文件、安装、删除软件等常用命令(持续更新)
    .NetCore3.1中的WebApi如何配置跨域
    PC电脑端如何多开Skype,一步搞定!
    简单几步为博客园添加动态动漫妹子
    如何在SqlServer中使用层级节点类型hierarchyid
    Entity framework Core 数据库迁移
    牛客网剑指offer【Python实现】——part1
    Linux实战——Shell编程练习(更新12题)
  • 原文地址:https://www.cnblogs.com/qq1312583369/p/11112371.html
Copyright © 2011-2022 走看看