java常用类之System类
- System类系统类,主要用于获取系统的属性数据和其他操作,构造方法私有。
方法名 | 说明 |
---|---|
static void arrayCopy(…) | 复制数组 |
static long currentTimeMillis() | 获取当前的系统时间,返回的是毫秒值 |
static void gc() | 建议JVM赶快启动垃圾回收器回收垃圾 |
static void exit(int status); | 退出JVM,如果参数为0表示正常退出JVM,非0表示异常突出JVM |
案例:
package hai.bok.strclass;
public class Test07 {
public static void main(String[] args) {
/**
* arraycopy 实现数组的复制
* src:源数组
* srcPos;从那个位置开始复制
* dest:目标数组
* destPos:目标数组的位置
* length:复制的长度
*/
int[] arr={20,18,38,65,2,99,13,45};
int[] dest=new int[8];
//1.复制数组
System.arraycopy(arr,0,dest,0,8);
for (int i = 0; i < dest.length; i++) {
System.out.println(dest[i]);
}
//2.获取毫秒数
long star=System.currentTimeMillis();
int result=0;
for (int i = 0; i < 9999; i++) {
result+=i;
}
long end=System.currentTimeMillis();
System.out.println("用时:"+(end-star));
//3.回收垃圾
new Student("aaa",20);
new Student("bbb",20);
new Student("ccc",20);
new Student("ddd",20);
System.gc();//告诉垃圾回收器回收。
//4.退出JVM
System.exit(0);
System.out.println("程序结束l");
}
}
常用类学习告一段落啦。完结,撒花!