java.lang.System类中提供了大量的静态方法,
可以获取与系统相关的信息或系统级操作
在System类的API文档中,常用的方法有:
-
public static long currentTimeMillis():返回以毫秒为单位的当前时间
-
public static void arrayCopy(Object src,int srcPos,Object dest,int destPos,int length):将指定源数组中的数组从指定位置复制到目标数组的指定位置
private static void demo01() {
/*
* public static long currentTimeMillis():返回以毫秒为单位的当前时间
* 计算for循环打印1到9999所需要使用的时间(毫秒)
* */
//执行前获取一次毫秒
long a = System.currentTimeMillis();
for (int i = 1; i <=9999; i++) {
System.out.println(i);
}
//执行后获取一次毫秒
long b = System.currentTimeMillis();
System.out.println("共耗时:"+(b-a)+"毫秒");//共耗时:105毫秒
}
private static void demo02() {
/*
* public static void arrayCopy(Object src,int srcPos,Object dest,int destPos,int length):
* 参数:
* Object src:原数组
* int srcPos:原数组中的要复制过去的起始位置
* Object dest:目标数组
* int destPos:被复制的起始位置
* int length:要复制的元素数量
* */
//原数组
int[] src = {1,2,3,4,5,6};
//目标数组
int[] dest = {3,2,1,4,5,6};
//复制前,[3, 2, 1, 4, 5, 6]
System.out.println(Arrays.toString(dest));
System.arraycopy(src,0,dest,0,3);
//复制后,[1, 2, 3, 4, 5, 6]
System.out.println(Arrays.toString(dest));
}