Java中System类的相关应用

1、Runtime:

 1 public class RuntimeDemo {
 2 
 3     public static void main(String[] args) {
 4         Runtime runtime=Runtime.getRuntime();
 5         System.out.println("最大容量"+runtime.maxMemory()/1024/1024+"MBytes");
 6         System.out.println("CPUs : "+runtime.availableProcessors());
 7         System.out.println("Free Memory: "+runtime.freeMemory()/1024/1024+"MBytes");
 8         System.out.println("Total Memory:"+runtime.totalMemory()/1024/1024+"MBytes");
 9     }
10 
11 }

2、Properties():

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

3、ArrayCopy

 1 import java.util.Arrays;
 2 
 3 public class ArrayCopy {
 4 
 5     public static void main(String[] args) {
 6         int[] data1 = {1, 2, 3, 4,5 };
 7         int[] data2 = new int[10];
 8         
 9         System.arraycopy(data1, 2, data2, 2, 3);
10         
11         System.out.println(Arrays.toString(data2));
12     }
13 
14 }
15 //结果显示:[0, 0, 3, 4, 5, 0, 0, 0, 0, 0]

猜你喜欢

转载自www.cnblogs.com/LJHAHA/p/10211121.html