1

I have no idea why eclipse is not printing anything on console while running this program.

public class StringOptimization {

    public StringOptimization() {

    }

    public static void main(final String[] args) {
        final StringOptimization optimization = new StringOptimization();
        final String sampleArray[] = new String[60000];
        for (int i = 0; i <= 50000; i++) {
            sampleArray[i] = "i";
        }
        final String finalString = optimization.addStringItems(sampleArray,
                true);
        System.out.println(finalString);
    }

    public String addStringItems(final String[] items,
            final boolean forceUpperCase) {
        final StringBuilder returnValue = new StringBuilder();
        for (final String item : items) {
            returnValue.append(item);
        }
        return forceUpperCase ? returnValue.toString().toUpperCase()
                : returnValue.toString();
    }
}
Ashish
  • 14,295
  • 21
  • 82
  • 127
  • Have you tried stepping through this with a debugger or at least adding more print statements to figure out where the program's execution differs from your expectations? – Kevin Workman Mar 24 '14 at 16:55
  • looks like it is limitation of eclipse or sysout because I can print value if I change it to 500 – Ashish Mar 24 '14 at 16:55
  • maybe you should wait a bit more, have you tried to put traces (println) in your loops ? – Joffrey Mar 24 '14 at 16:59
  • seems to stop printing if I change the array past size [4680] – Vince Mar 24 '14 at 17:02
  • have you run the program on commandline? Or done a print every 1000 appends or so? – deanosaur Mar 24 '14 at 17:04
  • possible duplicate of [System.out.print() doesn't send any output to Eclipse console. Why?](http://stackoverflow.com/questions/10948983/system-out-print-doesnt-send-any-output-to-eclipse-console-why) – Benoît Guédas Mar 24 '14 at 17:05

3 Answers3

2

There is a configurable limit to the number of characters kept in the Console, which normally is around 80000 characters. This mean that your line is printed and immediately discarded again.

Increase this setting in Preferences.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
1

Thank you for the hints Thorbjorn, setting the buffer limit did not work for me so I started playing with other option on the preference page and when I checked Fixed width console. eclipse started showing the output correctly. But I would still going to accept your answer because you pointed me in the correct direction.

enter image description here

Ashish
  • 14,295
  • 21
  • 82
  • 127
  • You should accept your answer anyway for posterity, because this is what actually works. Obviously, you should still upvote his answer ;) – Joffrey Mar 24 '14 at 17:10
  • I will accept my answer after 2 days SO would not let me do it now – Ashish Mar 24 '14 at 17:12
0

Increasing the console buffer size is OK. But in case if the maximum limit for the console buffer(equals to 1000000) also get exhausted then overwriting will happen again.

Other solution would be redirecting your console output to an external file. There is no size limit for this file. For longer build (like Maven builds etc) I use this method.

Refer these links

How can we redirect a Java program console output to multiple files?

redirecting to console

How to redirect

Note that at the same time you can redirect output to console and to an external file.

Community
  • 1
  • 1
Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68