Java System類兩個常用方法程式碼例項
阿新 • • 發佈:2020-02-27
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,9,0}; //把陣列a索引為3的位置往後2個數(8,5)複製到陣列b索引為2的位置上 System.arraycopy(a,3,b,2); System.out.println(Arrays.toString(b)); } }
執行結果:
注意:
(1)目標陣列原來位置上的數直接被覆蓋了。
(2)陣列索引從0開始。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。