System方法總結

來源:互聯網
上載者:User

1.System.arraycopy()

        int[] a = {1,2,3,4};
     int[] b = new int[5];
     
     /*for(int j = 0 ; j<a.length ; j++)
     {
     System.out.println("前:"+a[j]);
     }*/
     for(int j = 0 ; j<b.length ; j++)
     {
     System.out.println("前:"+b[j]);
     }
     
     System.out.println("--------------------------------------------------------");
     //public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
     //    拷貝對象,開始拷貝位置,拷貝到達對象,拷貝開始位置,拷貝長度
     //該方法的作用是數組拷貝,也就是將一個數組中的內容複寫到另外一個數組中的指定位置,
     //由於該方法是native方法,所以效能上比使用迴圈高效。
     System.arraycopy(a,1,b,2,3);
    
     /*for(int i = 0 ; i<a.length ; i++)
     {
     System.out.println("後:"+a[i]);
     }*/
     for(int i = 0 ; i<b.length ; i++)
     {
     System.out.println("後:"+b[i]);
     }

2.System.currentTimeMillis();

//獲得的將是一個長整型的數字,該數字就是以差值表達的目前時間,與格林尼治時間相比。
long start = System. currentTimeMillis();
        for(int i = 0;i < 100000000;i++){
                  int a = 0;
        }
        long end = System. currentTimeMillis();
        long time = end -start;
        System.out.println(end);
        System.out.println(start);
        System.out.println(time);

3.System.getProperty();

System.setProperty("love", "it is my love");
System.out.println(System.getProperty("love"));

/*public static String getProperty(String key)
該方法的作用是獲得系統中屬性名稱為key的屬性對應的值*/
System.out.println("java運行時環境版本:"+System.getProperty("java.version"));
System.out.println("java安裝目錄:"+System.getProperty("java.home"));
System.out.println("作業系統名稱:"+System.getProperty("os.name"));
System.out.println("作業系統版本:"+System.getProperty("os.version"));
System.out.println("使用者賬戶名稱:"+System.getProperty("user.name"));
System.out.println("使用者的主目錄:"+System.getProperty("user.home"));
System.out.println("目前使用者工作目錄:"+System.getProperty("user.dir"));

System.out.println("--------------------------------------------------------------");
Properties properties = System.getProperties();
for(Object key:properties.keySet()){    
            String keyStr=(String)key;    
            String value=properties.getProperty(keyStr);    
            System.out.println(keyStr+" --- "+value);    
        }    


System.out.println("***************************************************");

Properties pro = new Properties();
try {
pro.load(new FileInputStream(new File("D:\\workspace\\Static_final_Const\\src\\conf.properties")));
} catch (FileNotFoundException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
} catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}

System.out.println(pro.getProperty("base"));
System.out.println(pro.getProperty("i"));
System.out.println(pro.getProperty("w"));

4.System.exis

//public static void exit(int status)
//該方法的作用是退出程式。其中status的值為0代表正常退出,非零代表異常退出。
//使用該方法可以在圖形介面編程中實現程式的退出功能等


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.