System类

-System类常见的方法和案例

  1. exit退出当前程序
  2. arraycopy:复制数组元素,比较适合底层调用,一般用Arrays.copyOf完成复制数组。
  3. currentTimeMillens:返回当前时间距离1970-1-1的毫秒数
  4. gc:运行垃圾回收机制System.gc();
exit()

public class System_ {
   public static void main(String[] args) {
      System.out.println("hello");
      // System.exit(0); 表示程序退出
      // 0表示一个(正常)状态
      System.exit(0);
      System.out.println("java");
   }
}
System.arraycopy()
 public class System_ {
   public static void main(String[] args) {
      int[] arr={1,2,3};
      int[] arr2=new int[3];

      /*
      Params:
         src – the source array. // 源数组
         srcPos – starting position in the source array. // 从源数组的指定索引位置
         dest – the destination array.    // 拷贝到的目标数组的名称
         destPos – starting position in the destination data.  // 指定拷贝到目标数组的指定位置
         length – the number of array elements to be copied.   // 从源数组拷贝数据个数
       */
      System.arraycopy(arr,0,arr2,0,3);
      System.out.println("复制后的新数组:"+ Arrays.toString(arr2));
   }
}

 

posted @ 2024-07-07 18:22  Dr丶云幕  阅读(2)  评论(0编辑  收藏  举报