Java System.out.println () weird long string behavior

Can someone explain to me why this code does not print numbers?

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

Result

      SomeString

If I reduce the number of runs to 1000, it works, why ?! And also, if I add not only a number, but also a character, it works.

New update:

Thanks for the code examples. I tried all of them, but I found out that the console
 actually displays numbers, but only in fontcolor white. But the first part of the line   SomeStringis black.

I am using jdk1.7.0_06!

+5
source share
5 answers

This is an eclipse error. A fixed-width console locks the output.

+3
source

String.concat () takes a parameter String.

" ", , + , .

, 1499, .

0

, . .

-, Java . , int, :

  String text = new String("SomeString");

  for (int i = 0; i < 1500; i++) {
            text += i;
  }

  System.out.println(text);

-, - , int String :

  String text = new String("SomeString");

  for (int i = 0; i < 1500; i++) {
            text += Integer.toString(i);
  }

  System.out.println(text);
0

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

6 Java 6 Java 7.

0

, . . , JVM, , . ​​ Eclipse. , .

, i + "" i + ",", . , - Eclipse .

    String text = "SomeString";
    for (int i = 0; i < 15000; i++) {
        // text = text.concat(i + "");  // Doesn't display correctly
        // text += i;                   // Doesn't display correctly
        text = text.concat(i + ",");    // Displays correctly
        // text += i + ",";             // Displays correctly
    }
    System.out.println(text);

. !

UPDATE: I tried just printing the long string "xxxxxx" and found that up to 32,000 characters are displayed. When the line goes to 32001, it is not displayed. When I put "12345" + "xxxxxxxxx ...", I could still display 32000 characters of "x", which means the line length is more than 32000, so this has nothing to do with the total length of the line. This seems to be related to the length of the parts of the String objects.

0
source

All Articles