System类
- System系统类,主要用于获取系统的属性数据和其他操作,构造方法私有的。
arraycopy方法
public class SystemDemo {
public static void main(String[] args) {
//arraycopy:数组的复制
//System.arraycopy(src,srcPos,dest,destPos,length);
//src:源数组
//srcPos:从哪个位置开始复制 0
//dest:目标数组
//destPos:目标数组的位置
//length:复制的长度
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int[] dest = {11, 12, 13, 14, 15, 16, 17, 18, 19};
System.arraycopy(arr,0,dest,0,4);
for (int array:dest) {
System.out.print(array+"\t");
}
}
}
输出结果:
System.currentTimeMillis()方法
- 计算从1970.1.1到现在过去多少毫秒
- 可以用来计算程序运行耗时
//System.currentTimeMillis()
long start = System.currentTimeMillis();
System.out.println(start);
for (int i = 99999; i <999999 ; i++) {
for (int j = 99999; j <999999 ; j++) {
int result = i + j;
}
}
long end = System.currentTimeMillis();
System.out.println(end);
System.out.println("用时"+(end-start));