System
System的三大常量对象:
1.System.in:InputStream
2.System.out:PrintStream
3.System.err:PrintStream
System.currentTimeMillis():获取当前时间距离1970年1月1日午夜之间的时间差(毫秒)
System.arraycopy(src,srcPost,dest,destPost,int len)
第一个参数:要被复制(移动)的数组
第二个参数:从哪个位置开始复制(移动)
第三个参数:目标数组
第四个参数:目标的起始位置
第五个参数:要复制(移动的元素个数)
System.gc():通知垃圾回收器来回收垃圾,但是不是一调用就能来
RunTime:代表运行环境
RunTime对象.gc() 作用和System.gc()一样
maxMemory():返回虚拟机试图最大使用费内存
freeMemory():返回空闲内存
totalMemory():返回虚拟机的内存总量
public class TestSystem {
@org.junit.Test
//用System.arraycopy()实现删除数组中元素操作
public void test01(){
String [] arr=new String[5];
arr[0]="hello";
arr[1]="111";
arr[2]="222";
arr[3]="333";
arr[4]="444";
//删除arr[1]
int total=arr.length;//数组元素数量
int index=1;//要删除元素的下表
System.arraycopy(arr,index+1,arr,index,total-index-1);
//复制与目标数组都是arr,则只是更改arr自身,从arr[3]开始复制,所以第二个参数为index+1,
//第四个参数为index是表示从arr[1]这个分别位置插入arr[234]
arr[total-1]=null;//将最后一个元素设置为空
for (int i=0;i<arr.length;i++){
System.out.println(arr[i]);
}
}
@org.junit.Test
//要在arr[1]位置插入"array"
public void test02(){
String [] arr1=new String[5];
arr1[0]="000";
arr1[1]="111";
arr1[2]="222";
arr1[3]="333";
arr1[4]=null;
//要在arr[1]位置插入"array"
int total=4;//数组元素数量
int index=1;//要插入元素下标
System.arraycopy(arr1,index,arr1,index+1,total-index);
arr1[index]="array";
for (int i=0;i<arr1.length;i++){
System.out.println(arr1[i]);
}
}
}