System 类在 lang 包下,因此,不用导包;
主要有两个方法 ——
System.currentTimeMills( )
System.arraycopy(src, srcPos, dest, destPos, length)
public class test2 {
public static void main(String[] args) {
int t = 0;
long a1 = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
System.out.println(i);
}
long a2 = System.currentTimeMillis();
System.out.println("共花了" + (a2 - a1) + "毫秒");
int[] src = {1,2,3,4,5};
int[] dest = {6,7,8,9,10};
System.arraycopy(src,0,dest,0,3);
for (int i = 0; i < dest.length; i++) {
System.out.println(dest[i]);
}
}
}
共花了10毫秒
1
2
3
9
10
本文介绍Java中System类的使用方法,包括获取当前时间戳及数组复制。通过具体代码示例展示了如何利用System.currentTimeMillis()计算代码段执行时间,并使用System.arraycopy进行数组元素的复制。
1万+





