Ashish
Ashish

Reputation: 14707

Why there is no output is eclipse console

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();
    }
}

Upvotes: 1

Views: 624

Answers (3)

Chandrayya G K
Chandrayya G K

Reputation: 8849

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.

Upvotes: 0

Ashish
Ashish

Reputation: 14707

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

Upvotes: 1

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.

Upvotes: 2

Related Questions