Java學習筆記25(System類)

來源:互聯網
上載者:User

標籤:mem   sys   string   gpo   log   ack   start   body   art   

System類,系統類別,包含的是靜態方法,無法建立對象

這裡介紹幾個簡單的方法,其他一些在後邊用到的時候會講

類方法:

currentTimeMillis():擷取當前毫秒數

package demo;public class SystemDemo {    public static void main(String[] args) {        function();    }    // 這裡利用這個方法對程式效能進行測試    public static void function() {        long start = System.currentTimeMillis();        for (int i = 0; i < 666666; i++) {            System.out.println(i);        }        long end = System.currentTimeMillis();        System.out.println(end - start);        //輸出:4687      這裡表示運行了4687毫秒    }}

 

exit()方法:退出JVM虛擬機器

package demo;public class SystemDemo {    public static void main(String[] args) {        function();    }    public static void function() {        while (true) {            System.out.println("java");            System.exit(0);        }        // 這個死迴圈運抵第一次就會停止,只列印一遍java    }}

gc()方法:收取對象的垃圾,這個不需要舉例,知道即可

getProperties()方法:擷取當前作業系統的屬性,並沒有什麼實際用途,瞭解即可

 

arraycopy方法:複製數組

package demo;public class SystemDemo {    public static void main(String[] args) {        function();    }    public static void function() {        int[] src = {1,2,3,4,5,6};        int[] desc = {7,8,9,0};        System.arraycopy(src, 1, desc, 1, 2);        for (int i = 0; i < desc.length; i++) {            System.out.println(desc[i]);        }        //輸出:7    2    3    0    }}/*這裡幾個參數:Object src:要複製的原數組int srcPos:數組源的起始索引Object dest:複製後的目標數組int destPos:目標數組起始索引int length:複製幾個*/

 

Java學習筆記25(System類)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.