黑马程序员技术交流社区
标题:
【记录】代码练习-System类
[打印本页]
作者:
Kevin.Kang
时间:
2015-7-8 14:58
标题:
【记录】代码练习-System类
package Day14_System;
import java.util.Arrays;
public class SystemDemo {
public static void main(String[] args) {
// System类包含一些有用的类字段和方法,它不能被实例化。
// 方法:
// public static void gc():手动运行垃圾回收器
Person person = new Person("古天乐", 21);// 创建一个对象
System.out.println(person);
person = null;// 取消指向堆内存,上面堆内存中的对象就变成了垃圾
// System.gc();// 手动运行垃圾回收器
// public static void exit():退出JVM
System.out.println("呵呵");
// System.exit(0);// 0表示退出,非0是异常终止
System.out.println("嘿嘿");
// public static long currentTimeMillis():返回以毫秒为单位的当前时间
long start = System.currentTimeMillis();
int count = 0;
for (int x = 0; x < 100000; x++) {
count++;
}
long end = System.currentTimeMillis();
// 可以用来计算程序运行需要花费多长时间
System.out.println("程序运行时间:" + (end - start) + "毫秒");
// public static void arraycopy(Object src,int srcPos,Object dest,int
// destPos,int length):从指定源数组中复制一个数组,复制从指定的位置开始,到目标数组的指定位置结束
int[] arr = { 1, 3, 5, 7, 9 };
int[] arr2 = { 2, 4, 6, 8, 10 };
System.arraycopy(arr, 1, arr2, 2, 3);
System.out.println(Arrays.toString(arr2));
}
}
复制代码
作者:
加多宝
时间:
2015-7-8 15:03
这代码虽说基础,但看着有点晕
作者:
122125241
时间:
2015-7-8 15:18
重新回忆了一点- - 唉
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2