返回列表 發帖
  1. public class Ch01 {
  2.         long s , e;
  3.         Ch01()
  4.         {
  5.                 s=System.currentTimeMillis();
  6.                 test2();
  7.                 e=System.currentTimeMillis();
  8.                 System.out.println("花費: "+(e-s)+" 毫秒");
  9.         }

  10.         void test1()
  11.         {
  12.                 for(int i=1; i<=10000; i++)
  13.                         System.out.println(i);
  14.                 System.out.println();
  15.         }

  16.         void test2()
  17.         {
  18.                 StringBuilder sb=new StringBuilder();
  19.                 for(int i=1; i<=10000; i++)
  20.                         sb.append(i+"\n");
  21.                 System.out.println(sb);
  22.         }

  23.         void test3()
  24.         {
  25.                 String str="";
  26.                 for(int i=1; i<=10000; i++)
  27.                         str=i+"\n";
  28.                 System.out.println(str);
  29.         }

  30.         public static void main(String[] args) {
  31.                 new Ch01();
  32.         }
  33. }
複製代碼

TOP

返回列表