1.System类概述:
java.lang.System类中提供了大量的静态方法,可以获取与系统相关的信息或系统操作
2.System类的方法:
- public static void exit(int status) 终止当前运行的java虚拟机,非零表示异常终止
System.out.println("程序开始");
System.out.println("程序执行");
//System.exit(0); //程序正常退出(默认的)
System.exit(1); //程序非正常退出(后面的0会变成1)
System.out.println("程序结束");
- public static long currentTimeMillis() 返回当前时间距离标准基准时间的毫秒值
//获取当前时间距离标准基准时间的毫秒值
// 第一种使用Date获取
Date date = new Date();
long time = date.getTime();
System.out.println(time);
//第二种使用System获取
System.out.println(System.currentTimeMillis());
- public static void arrayCopy(Object src,int srcPos,Object dest,int destPos,int length)
拷贝数组中的元素到另一个数组
参数1 src:源数组
参数2 srcPos:源数组要拷贝的元素的起始索引(从哪个索引位置开始拷贝)
参数3 dest:目标数组
参数4 destPos:目标数组接收拷贝元素的起始索引(从哪个索引位置开始接收)
参数5 length:需要替换多少个元素
public static void show(int[] arr){
for (int i = 0 ; i<arr.length; i++){
System.out.print(arr[i]+" ,");
}
// 拷贝数组元素到另一个数组中区
int [] arr1 = {10,20,30,40,50};
int [] arr2 = {11,22,33,44,55,66,77,88,99};
System.arraycopy(arr1,1,arr2,2,3);
show(arr2);