Java中System类的相关应用

1、Runtime:

 public class RuntimeDemo {

     public static void main(String[] args) {
Runtime runtime=Runtime.getRuntime();
System.out.println("最大容量"+runtime.maxMemory()/1024/1024+"MBytes");
System.out.println("CPUs : "+runtime.availableProcessors());
System.out.println("Free Memory: "+runtime.freeMemory()/1024/1024+"MBytes");
System.out.println("Total Memory:"+runtime.totalMemory()/1024/1024+"MBytes");
} }

2、Properties():

 import java.util.Enumeration;
import java.util.Properties; public class SysInfo {
public static void main(String[] args) {
Properties properties=System.getProperties();//getProperties()用于获取当前系统的全部属性
Enumeration<?> propertyNames=properties.propertyNames();
while(propertyNames.hasMoreElements()) {
String key=(String)propertyNames.nextElement();
String value=System.getProperty(key);//System.getProperty()获得指定键描述的系统属性
System.out.println(key+"---->"+value);
}
// System.out.println("Java Version:"+System.getProperty("java.version"));
// System.out.println("OS Name:"+System.getProperty("os.name"));
// System.out.println("OS Version:"+System.getProperty("os.version"));
}
}

3、ArrayCopy

 import java.util.Arrays;

 public class ArrayCopy {

     public static void main(String[] args) {
int[] data1 = {1, 2, 3, 4,5 };
int[] data2 = new int[10]; System.arraycopy(data1, 2, data2, 2, 3); System.out.println(Arrays.toString(data2));
} }
//结果显示:[0, 0, 3, 4, 5, 0, 0, 0, 0, 0]
上一篇:AMBA总线介绍


下一篇:学了这么久,vue和微信小程序到底有什么样的区别?