Performance Checklist
Most of these suggestions apply only after a bottleneck has been identified:
Logically partition your strings into those that require internationalization support (i.e., text) and those that don’t.
Avoid internationalization where the
Strings never require it.
Avoid using the
StreamTokenizer.Create and optimize your own framework to convert objects and primitives to and from strings.
Use efficient methods of
Stringthat do not copy the characters of the string, e.g.,String.substring().Avoid using inefficient methods of
Stringthat copy the characters of the string, e.g.,String.toUppercase()andString.toLowercase( ).Use the string concatenation operator to create
Strings at compile time.Use
StringBuffers to createStrings at runtime.Specify when the underlying
chararray is copied when reusingStringBuffers.
Improve access to the underlying
Stringchararray by copying thechars into your own array.Manipulate characters in
chararrays rather than usingStringandStringBuffermanipulation.Reuse
chararrays.
Optimize the string comparison and search algorithm for the data being compared and searched.
Compare strings by identity.
Convert a comparison task to a (hash) table lookup.
Handle case-insensitive comparisons differently from case-sensitive comparisons.
Apply the standard performance optimization for case-insensitive access (maintaining a second collection with all strings uppercased).
Use
java.text.CollationKeys rather than ajava.text.Collatorobject to sort ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access