Java学习记录之System系统类

java.lang.System类中提供了大量的静态方法,可以获取与系统相关的信息或系统级操作,在System类的API文档中,常用的方法有:
public static long currentTimeMillis():返回以毫秒为单位的当前时间
public static void arraycopy(Object src,int srcPos, Object dest, int destPos, int length):将数组中指定的数据拷贝到另一个数组中

public class Demo01System{
   public static void main(String[] args){
      demo01();
   }
   /*
      public static long currentTimeMillis(): 返回以毫秒为单位的当前时间。
      可用来测量程序运行的时间
      验证for循环打印数字1-9999所需要使用的时间(毫秒)
   */
   private static void demo01(){
      //程序执行前,获取一次毫秒值
      long s = System.currentTimeMillis();
      //执行for循环
      forint i=1;i<=9999;i++{
            System.out.println(i);
       }
       //程序执行后,获取一次毫秒值
       long e = System.currentTimeMillis();
       System.out.println("程序共耗时:"+(e-s)+"毫秒")}

   /*
      public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length):将数组中指定的数据拷贝到另一个数组中
      参数:
          src :源数组
          srcPos :源数组中的起始位置(起始索引)
          dest :目标数组
          destPos:目标数组的起始位置
          length :要复制的数组元素的数量
       练习:
          将src数组中前3个元素,复制到dest数组的前3个位置上
          复制元素前:
          src数组元素[1,2,3,4,5],dest数组元素[6,7,8,9,10]
          复制元素后:
          src数组元素[1,2,3,4,5],dest数组元素[1,2,3,9,10]
   */
    private static void demo02(){
       //定义源数组
       int[] src = {1,2,3,4,5};
       //定义目标数组
       int[] dest = {6,7,8,9,10};
       //使用Array.toString()方法让数组变成字符串输出
       System.out.println("复制前:"+Array.toString(dest));
       System.arraycopy(src,0,dest,0,3);
       System.out.println("复制后:"+Array.toString(dest));
       
    }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值