Java 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開始。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章:
