java.lang.System 類中提供了大量的靜態方法,可以獲取與系統相關的信息或系統級操作,在System類的API文 檔中,常用的方法有: public static long currentTimeMillis() :返回以毫秒爲單位的當前時間。
public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) :將 數組中指定的數據拷貝到另一個數組中。
currentTimeMillis方法
實際上,currentTimeMillis方法就是 獲取當前系統時間與1970年01月01日00:00點之間的毫秒差值
public static void main(String[] args) {
System.out.println(System.currentTimeMillis());
Date date=new Date(1000);
System.out.println(date);
date.setTime(System.currentTimeMillis());
System.out.println(date);
}
練習
驗證for循環打印數字1-9999所需要使用的時間(毫秒)
arraycopy方法
public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) :將 數組中指定的數據拷貝到另一個數組中。
數組的拷貝動作是系統級的,性能很高。System.arraycopy方法具有5個參數,含義分別爲:
練習
將src數組中前3個元素,複製到dest數組的前3個位置上
複製元素前:src數組元素[1,2,3,4,5],dest數組元素 [6,7,8,9,10]
複製元素後:src數組元素[1,2,3,4,5],dest數組元素[1,2,3,9,10]