黑马程序员技术交流社区

标题: 【记录】代码练习-System类 [打印本页]

作者: Kevin.Kang    时间: 2015-7-8 14:58
标题: 【记录】代码练习-System类
  1. package Day14_System;

  2. import java.util.Arrays;

  3. public class SystemDemo {
  4. public static void main(String[] args) {
  5. // System类包含一些有用的类字段和方法,它不能被实例化。
  6. // 方法:
  7. // public static void gc():手动运行垃圾回收器
  8. Person person = new Person("古天乐", 21);// 创建一个对象
  9. System.out.println(person);
  10. person = null;// 取消指向堆内存,上面堆内存中的对象就变成了垃圾
  11. // System.gc();// 手动运行垃圾回收器

  12. // public static void exit():退出JVM
  13. System.out.println("呵呵");
  14. // System.exit(0);// 0表示退出,非0是异常终止
  15. System.out.println("嘿嘿");

  16. // public static long currentTimeMillis():返回以毫秒为单位的当前时间
  17. long start = System.currentTimeMillis();
  18. int count = 0;
  19. for (int x = 0; x < 100000; x++) {
  20. count++;
  21. }
  22. long end = System.currentTimeMillis();
  23. // 可以用来计算程序运行需要花费多长时间
  24. System.out.println("程序运行时间:" + (end - start) + "毫秒");

  25. // public static void arraycopy(Object src,int srcPos,Object dest,int
  26. // destPos,int length):从指定源数组中复制一个数组,复制从指定的位置开始,到目标数组的指定位置结束
  27. int[] arr = { 1, 3, 5, 7, 9 };
  28. int[] arr2 = { 2, 4, 6, 8, 10 };
  29. System.arraycopy(arr, 1, arr2, 2, 3);
  30. System.out.println(Arrays.toString(arr2));
  31. }
  32. }
复制代码


作者: 加多宝    时间: 2015-7-8 15:03
这代码虽说基础,但看着有点晕
作者: 122125241    时间: 2015-7-8 15:18
重新回忆了一点- -  唉




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2