System类的常用方法
生活随笔
收集整理的這篇文章主要介紹了
System类的常用方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
package com.learn.demo05.System;import java.util.Arrays;/*java.lang.System類中提供了大量的靜態方法,可以獲取與系統相關的信息或系統級操作,在System類的API文檔中,常用的方法有:public static long currentTimeMillis():返回以毫秒為單位的當前時間。public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length):將數組中指定的數據拷貝到另一個數組中。*/
public class Demo01System {public static void main(String[] args) {demo02();StringBuilder sb = new StringBuilder();}/*public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length):將數組中指定的數據拷貝到另一個數組中。參數:src - 源數組。srcPos - 源數組中的起始位置(起始索引)。dest - 目標數組。destPos - 目標數據中的起始位置。length - 要復制的數組元素的數量。練習:將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]*/private static void demo02() {//定義源數組int[] src = {1,2,3,4,5};//定義目標數組int[] dest = {6,7,8,9,10};System.out.println("復制前:"+ Arrays.toString(dest));//使用System類中的arraycopy把源數組的前3個元素復制到目標數組的前3個位置上System.arraycopy(src,0,dest,0,3);System.out.println("復制后:"+ Arrays.toString(dest));}/*public static long currentTimeMillis():返回以毫秒為單位的當前時間。用來程序的效率驗證for循環打印數字1-9999所需要使用的時間(毫秒)*/private static void demo01() {//程序執行前,獲取一次毫秒值long s = System.currentTimeMillis();//執行for循環for (int i = 1; i <=9999 ; i++) {System.out.println(i);}//程序執行后,獲取一次毫秒值long e = System.currentTimeMillis();System.out.println("程序共耗時:"+(e-s)+"毫秒");//程序共耗時:106毫秒}
}
?
總結
以上是生活随笔為你收集整理的System类的常用方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Calendar类的常用成员方法
- 下一篇: StringBuilder的构造方法和a