String
s are constructed (including the first, empty String
) because each time the following statement executes, a new String
is created: rev += data.charAt(j);As the statement starts to execute,
rev
refers to a String
. The concatenation operator +
creates a new String
, a copy of the old one but with one more character on the end. The new String
reference is assigned to rev
. The old String
is now garbage. This is fine for programs that do a moderate amount of character manipulation. But such abundant construction of objects will slow down a program that does a great deal of character manipulation. Examples of such programs include word processors, compilers, assemblers, data base management systems, and many others.
No comments:
Post a Comment