返回列表 發帖
  1. public class Ch49 {
  2.     long s,e;
  3.         Ch49() throws Exception
  4.         {
  5.                 s=System.currentTimeMillis();
  6.                 test1();
  7.                 test2();
  8.                 test3();
  9.                
  10.                
  11.                 e=System.currentTimeMillis();
  12.         System.out.println("use"+(e-s)+"毫秒");
  13.         
  14.         }
  15.         void test1()
  16.         {
  17.                 for(int i=1;i<=10000;i++)
  18.                         System.out.println(i);
  19.                 System.out.println();
  20.         }
  21.        
  22.         void test2()
  23.         {
  24.                 StringBuilder sb=new StringBuilder();
  25.                 for(int i=1;i<=10000;i++)
  26.                         sb.append(i+"\n");
  27.                 System.out.println(sb);
  28.         }
  29.        void test3()
  30.        {
  31.                String str="";
  32.                for(int i=1;i<=10000;i++)
  33.                 str+=i+"\n";
  34.                System.out.println(str);
  35.        }
  36.        public static void main(String[] args)
  37.        {
  38.          new Ch49();
  39.        }
  40.       
  41.         }
複製代碼

TOP

返回列表