zoukankan      html  css  js  c++  java
  • Java System类

    System类概述

    System类包含一些有用的类字段和方法,它不能被实例化

    成员方法

    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 
    
  • 相关阅读:
    修改 MySQL 的 sql_mode 模式方法
    PHP 实现 Redis 连接池
    【转载】php解决高并发问题
    PHP 7 不适用函数:password_hash
    PDO 防止 SQL 注入示例
    记录一次 header 参数格式引发的错误
    Laravel 框架数据库查询构造器中 when 的易犯错误
    PHP 7.3.4 安装 Redis 4.0(Windows系统)
    汇编语言全梳理(精简版)
    Anaconda安装和使用
  • 原文地址:https://www.cnblogs.com/bbn0111/p/7506503.html
Copyright © 2011-2022 走看看