java --System類的常用方法

System類

java.lang.System

public final class System extends Object

System 類包含一些有用的類字段和方法。它不能被實例化。
在 System 類提供的設施中,有標準輸入、標準輸出和錯誤輸出流;對外部定義的屬性和環境變量的訪問;加載文件和庫的方法;還有快速複製數組的一部分的實用方法。

從以下版本開始:
JDK1.0

常用方法

(1) arraycopy

static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
從指定源數組中複製一個數組,複製從指定的位置開始,到目標數組的指定位置結束。
     參數: 
     src - 源數組  srcPos - 源數組中的起始位置
     dest - 目標數組   destPos - 目標數據中的起始位置
     length - 要複製的數組元素的數量
private static void show01() {
        int[] a = {3,5,6,7,8};
        int[] b = new int[5];
        System.arraycopy(a,1,b,1,2);
        for(int i : b){
            System.out.print(i +" ");//0 5 6 0 0
        }
    }

(2) currentTimeMillis

static long currentTimeMillis()
返回以毫秒爲單位的當前時間。
當前時間與協調世界時 1970 年 1 月 1 日午夜之間的時間差(以毫秒爲單位測量)。
  private static void show02() {
        long time = System.currentTimeMillis();
        System.out.println(time);//1585926487767
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章