System类的基础知识整理

Java.lang.System类中提供了大量的静态方法,可以获取系统相关的信息或进行系统级的操作。

currentTimeMillis方法

public static lang currentTimeMillis():返回以毫秒为单位的当前时间。

/**
 * @description: System类方法测试
 * @author: Murphy
 * @date: 2020/6/309:58 上午
 */
public class SystemDemo {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 500000; i++) {
            int a = 0;
            int b = a + i;
        }
        long end = System.currentTimeMillis();
        //得到for循环的运算时间
        System.out.println(end - start);
    }
}

arraycopy方法

public static void arraycopy( Object src, int srcPos, Object dest, int destPos, int length):将数组中指定的数据拷贝到另一个数组中。

数组的拷贝动作是系统级的,性能很高,该方法有五个参数,含义如下:

参数含义
Object src源数组
int srcPos源数组索引起始位置
Object dest目标数组
int destPos目标数组索引起始位置
int length复制元素个数
/**
 * @description: System类方法测试
 * @author: Murphy
 * @date: 2020/6/309:58 上午
 */
public class SystemDemo {
    public static void main(String[] args) {
        int[] a = {1, 2, 3, 4, 5, 6};
        int[] b = {7, 8, 9, 10, 11, 12};
        System.arraycopy(a, 0, b, 0, 3);
        for (int i = 0; i < b.length; i++) {
            System.out.print(b[i]+"  ");
        }
    }
}
//输出结果:1  2  3  10  11  12  

exit方法

public static void exit(int status):终止当前正在运行的java虚拟机。

status状态码非零时表示异常终止。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值