System类的两个常用方法

1.System.currentTimeMills():得到当前时间距离时间原点的毫秒数,返回值是Long类型的整数。

代码演示:

public class Demo4 {
    public static void main(String[] args) {
        long l = System.currentTimeMillis();
        System.out.println(l);
    }
}

运行结果:

2.System.arrayCopy(src,srcpos,des,despos,length):将原数组src中srcpos位置及其后面length长度的数复制给目标数组des的despos位置。

代码演示:

import java.util.Arrays;

public class Demo4 {
    public static void main(String[] args) {
        int[] a={3,7,1,8,5};
        int[] b={11,2,16,7,9,0};
        //把数组a索引为3的位置往后2个数(8,5)复制到数组b索引为2的位置上
        System.arraycopy(a,3,b,2,2);
        System.out.println(Arrays.toString(b));
    }
}

运行结果:

 注意:

(1)目标数组原来位置上的数直接被覆盖了。

(2)数组索引从0开始。

猜你喜欢

转载自www.cnblogs.com/iceywu/p/12016908.html