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 
    
  • 相关阅读:
    用flask实现的分页
    用flask的扩展实现的简单的页面登录
    基于DBUtils实现数据库连接池
    Flask基础
    Flask入门
    发消息示例
    反向找related_name以及limit_fields_to
    对于stark(curd)插件的使用简单介绍
    列表的append方法和extend方法
    函数和方法的区别
  • 原文地址:https://www.cnblogs.com/bbn0111/p/7506503.html
Copyright © 2011-2022 走看看