欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

(Java基础类库 )System类

程序员文章站 2024-01-20 17:47:10
...

(Java基础类库 )System类

 System类中定义有许多方法

  • 数组拷贝:public static void arrayCopy(Objec src,int srcPos,Object dest,int destPos,int length);
  • 获取当前的日期时间数值:public static long currentTimeMillis();
  • 进行垃圾回收:public static void gc();

范例:操作耗时的统计

package Java基础类库;

public class Runtime类 {
	public static void main(String[] args) {
		long start = System.currentTimeMillis();//获取开始的时间
		 System.out.println("----------用for循环产生大量垃圾----------");
		 String str ="";
		 for(int x= 0;x<30000;x++) {
			 str+=x;
		 }
		 long end = System.currentTimeMillis();//获取结束的时间
		 System.out.println("耗时为:"+(end-start));
	}
}
  

----------用for循环产生大量垃圾----------
耗时为:1232

在System类里面也提供有gc()方法,这个方法只是调用了Runtime类中的gc()方法。