Java 之 System 类

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

常用方法1:

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

  该方法获取当前系统时间与 1970年01月01日00:00点之间的毫秒差值

常用方法2:

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

   数组的拷贝动作是系统级的,性能很高。

   System.arraycopy 方法具有5个参数,含义分别为:

参数序号 参数名称 参数类型 参数含义
1 src Object 源数组
2 srcPos int 源数组索引起始位置
3 dest Object 目标数组
4 destPos int 目标数组索引起始位置
5 length int 复制元素个数

  Demo:

 1 import java.util.Arrays;
 2 
 3 public class Demo11SystemArrayCopy {
 4     public static void main(String[] args) {
 5         int[] src = new int[]{1,2,3,4,5};
 6         int[] dest = new int[]{6,7,8,9,10};
 7         System.arraycopy( src, 0, dest, 0, 3);
 8         /*代码运行后:两个数组中的元素发生了变化
 9          src数组元素[1,2,3,4,5]
10          dest数组元素[1,2,3,9,10]
11         */
12     }
13 }

猜你喜欢

转载自www.cnblogs.com/niujifei/p/11415401.html