The only way these methods could be slow is by the getter methods of ExtensionInfoRec or CustomizeRecItem being slow. BTW, using StringBuffer doesn't buy you anything here. Using String would be as fast and improve readability. Why do you think you need to improve performance of these methods?
strAliasName.append("REP_PRO").append("_").append(extInfo.getColName()); But use String instead of above , doesn't it create 3862*3 Strings here ?? [ July 02, 2003: Message edited by: Javan Li ]
No - the typical Java compiler uses a single StringBuffer for all String concatenations in an expression. For example "REP_PRO" + "_" + extInfo.getColName() would be *identical* to new StringBuffer().append("REP_PRO").append("_").append(String.valueOf(extInfo.getColName)).toString()
Originally posted by James Fisk: static final String onlyCreatedOnce= "REP_PRO_";
String newString = onlyCreatedOnce + (new stuff)
Doesn't buy you anything, too. As stated by the Java Language Specification, String literals are put into a pool and reused throughout the application. Try System.out.println("myString" == "myString"); You should get "true" as output, as both literals are resolved to the *same* String object in the constant pool. There is no instanciation overhead involved at all!
he had TWO concatenation operators in his expression. each concatenation creates a NEW STRING Nope. The JLS allows an implementation to be smart enough to not create an intermediate String if there's no real need. And any decent compiler will take advantage of this permission. If a concatenation is followed immediately by another concatenation, the compiler knows that there's no use for the intermediate String, and so doesn't create one. If the program logic had been a bit more complex, then there might have been a benefit to using StringBuffer rather than + concatenation - but as it is, there is no benefit.
Additionally, "REP_PRO" + "_" is a Compile Time Constant Expression and therefore evaluated at compile time, not at runtime - I missed that in my first post... So "REP_PRO" + "_" + extInfo.getColName() would in fact be identical to new StringBuffer().append("REP_PRO_").append(String.valueOf(extInfo.getColName)).toString() !!!
Post by:autobot
Look! It's Leonardo da Vinci! And he brought a tiny ad!
a bit of art, as a gift, that will fit in a stocking