java System.out.println() strange behavior long string

前端 未结 5 1325
再見小時候
再見小時候 2021-01-12 17:31

Can somebody explain me why this code does not print the numbers?

      String text = new String("SomeString");
      for (int i=0; i<1500; i++)          


        
5条回答
  •  抹茶落季
    2021-01-12 18:06

    To do the same more efficiently

      StringBuilder text = new StringBuilder("SomeString");
      for (int i = 0; i < 1500; i++) {
            text.append(i);
      }
      System.out.println(text);
    

    Both examples work for me on Java 6 update 32 and Java 7 update 3.

提交回复
热议问题