常用API之System类的使用(学习Java第15天)

System类的概述

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

System类的常用方法

public static void exit(int status) 终止当前运行的Java虚拟机,非零表示异常终止
public static long currentTimeMillis() 返回当前时间距离标准基准时间的毫秒值
static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) 拷贝数组中的元素到另一个数组
      参数1src: 源数组
      参数2srcPos:源数组要拷贝的元素的起始索引(从哪个索引位置开始拷贝)
      参数3dest: 目标数组
      参数4destPos:目标数组接收拷贝元素的起始索引(从哪个索引位置开始接收)
      参数5length:需要拷贝多少个元素(拷贝多少个)

案例代码 

public class Demo {
    public static void main(String[] args) {
       /* System.out.println("Hello World!1");
        System.out.println("Hello World!2");
        // 结束程序运行
        System.exit(0);
        System.out.println("Hello World!3");*/


        System.out.println("==========================================");
        long time = System.currentTimeMillis();
        System.out.println("time:"+time);

        long time2 = new Date().getTime();
        System.out.println("time2:"+time2);

        System.out.println("==========================================");
        int[] src = {1,2,3,4,5,6,7};
        int[] dest = {10,20,30,40,50,60,70};

        // 需求:把src数组中的2,3,4拷贝到dest目标数组中,使得目标数组的元素为:{10,20,30,2,3,4,70};
        System.arraycopy(src,1,dest,3,3);

        // System.out.println("源数组:"+Arrays.toString(src));
        // System.out.println("目标数组:"+Arrays.toString(dest));
        for (int i = 0; i < dest.length; i++) {
            System.out.println(dest[i]);
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值