Originally posted by JeanMichel Hanquet:
Now, talking about Assignment 1.1, would it be more efficient/faster/cheaper to
1. build 1 big string and use System.out.println( myBigString ) and the end of the loop to print it out on the screen
2. print out the words as I go through the loop invoking System.out.println( myWordToPrint ) each time.
It seems to me that printing on the screen is more CPU consuming. Up to a point where String manipulation becomes more of an issue.
Jm
I thought it would be better to start a new
thread for this question.
You are right - the current implementation of System.out.println() is slow.� But!� That is external to your program.� Most programs you write will not have to be concerned with the console.
You should assume that System.out.print() is lightning fast.
The fact that every time you concatenate two Strings you are creating 4 objects is a much bigger deal. Object creation is very costly.