System类基础

时间:2022-10-13 18:19:08

取时间差:

public class SystemDemo01 {
    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < 1000; i++) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        long endTime = System.currentTimeMillis();

        System.out.println("Time costed: " + (endTime - startTime));
    }
}

取系统参数:

public class SystemDemo02 {
    public static void main(String[] args) {
        System.getProperties().list(System.out);
    }
}