笔记:System

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]);
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值