面试问到Java常用类:System类,这也太偏门了吧!

System 系统类主要用于获取系统的属性数据和其他操作,构造方法私有

常用方法

方法名说明
static void arraycopy();复制数组
static long currentTimeMillis();获取当前系统时间,返回的是毫秒值
static void exit(int status);退出 jvm,如果参数是0表示正常退出jvm,非0表示异常退出 jvm
arraycopy();方法

实例:

import java.util.Arrays;

public class Demo01 {

    public static void main(String[] args) {

        //arraycopy();数组复制
        //System.arraycopy(src, srcPos, dest, destPos, length);
        //src:源数组,scrPos:从哪里位置开始复制,dest:目标数组
        //destPos:目标数组位置,length:复制的长度

        int[] arr = {23,32,45,2,36,90,18,190};//源数组
        int[] dest = new int[8];//目标数组
        System.out.println("dest复制前:"+Arrays.toString(dest));
        System.arraycopy(arr,0,dest,0,arr.length);//dest数组复制arr数组
        System.out.println("dest复制后:"+Arrays.toString(dest));
        
    }

}

输出

dest复制前:[0, 0, 0, 0, 0, 0, 0, 0]
dest复制后:[23, 32, 45, 2, 36, 90, 18, 190]
currentTimeMillis(); 方法

示例:

public class Demo02 {

    public static void main(String[] args) {

        //常用来记录代码运行时间
        long star = System.currentTimeMillis();//获取当前时间
        for (int i = 0; i < 99999999; i++) {
            for (int j = 0; j < 99999999; j++) {
                int result = i + j;
            }
        }
        long end = System.currentTimeMillis();//获取当前时间
        System.out.println("运行时间:"+(end - star)+" ms");

    }

}

输出

运行时间:8 ms
exit(); 方法

示例:

public class Demo03 {

    public static void main(String[] args) {

        System.exit(0);//提前退出
        System.out.println("text");

    }

}

输出为空

最后,祝大家早日学有所成,拿到满意offer,快速升职加薪,走上人生巅峰。记得给我一个一键三连哦!老子爱你们!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值