Wednesday, September 8, 2010

Improve your Java code performance

1. JDK 1.5 and above provide some new features to replace some old implementations:

  • StringBuilder is a replacement of StringBuffer

StringBuffer instances are almost always used by a single thread,yet they perform

internal synchronization. It is for this reason that was essentially replaced by StringBuilder,

which is an unsynchronized

  • Vector and ArrayList, if you create and modify the Vector within a method, ArrayList

will have better performance

2. If you only need read data from a collection, Collections.unmodifiable() will return the read-only view of

the passed in colleciton, you don't need to create a copy of the data, and you will consume less memory,

make less impact on garbage collector, and make the program faster.

Posted via email from Progress

No comments:

Post a Comment