system下的currentTimeMillis()与arraycopy方法!

#system类下的方法

currentTiemMills()方法

代码(程序运行时间举例):

public class Demo01System {
public static void main(String[] args) {
    long s=System.currentTimeMillis();//返回当前时间,以秒计算。
    int  sum=0;
    for (int i = 0; i < 9999; i++) {
        sum=sum+i;
        if (i!=9998)
        System.out.print(i+",");
        else
            System.out.println(i);
    }
    System.out.println();
    System.out.println(sum);
    long e=System.currentTimeMillis();
    System.out.println("程序运行的时间为:"+(e-s)+"毫秒");
}
}

运行效果
//省略
程序运行的时间为:111毫秒

arraycopy方法

代码:

public class Demo02SystemArrayCopy {
public static void main(String[] args) {
    int[] src={1,2,3,1,1,0};
    int[] dest={45,4,5,5,2,0};
    System.out.println(Arrays.toString(dest));
    System.arraycopy(src,0,dest,1,3);
    System.out.println("复制后:"+ Arrays.toString(dest));
}
}

注:
System.arraycopy(src,0,dest,1,3);
src代表的是来源的数组(被复制的数组),后面的0代表的是其开始复制的起始位置是数组的第一个元素,dest是要复制的数组,1代表从第二个位置开始被替代。最后的3表示要复制的长度。返回值是dest数组
显示效果:
[45, 4, 5, 5, 2, 0]
复制后:[45, 1, 2, 3, 2, 0]

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值