System
首先编译期间开始初始化,初始化方法在initializeSystemClass中
类中主要一下几个功能
(1)系统信息的访问,如外部属性和环境变量等
//可以打印出所有system的参数,也可以添加参数进系统中
System.setProperty("user.name","你好");
System.getProperties().forEach((k,v)->{
System.out.println(k+" "+v);
});
//如何程序中有需要用到当前目录的,就可以使用到此方法
System.getProperty("user.dir");
ArrayList<String> stringList = new ArrayList<>();
//实际还是 Runtime.getRuntime().gc();建议vm gc,还是可能会被拒绝的
System.gc();
//获得本地环境变量配置的值
System.out.println("kangenv"+System.getenv("TEMP"));
//返回当前时间
System.out.println("当前时间戳"+System.currentTimeMillis());
System.out.printf("纳秒时间 和java随机数有关"+System.nanoTime());
(2)垃圾回收相关操作
//实际还是 Runtime.getRuntime().gc();建议vm gc,还是可能会被拒绝的
System.gc();
(3)标准输入输出,主要是
属性in,out,error
(4)比较常用的其他操作,比如数组拷贝,调用的是本地navice方法
//数组拷贝,arraylist动态扩容就是调用此方法 依次是源数组 开始复制下边 目标数组 开始替换下标 替换长度
//Params:
// src – the source array.
// srcPos – starting position in the source array.
// dest – the destination array.
// destPos – starting position in the destination data.
// length – the number of array elements to be copied
int[] a = {1,2,3,4,5};
int[] b ={2,3,4,5,7};
System.arraycopy(a,2,b,2,2);
System.out.println("arraycopy"+ Arrays.toString(b));