I find my self constantly changing my utility methods to improve string handling in my Java code. For example I have changed bunch of my search and replace code to use commons StringUtils.replace method. Or upgrading 1.4 to 1.6 java to type safe code.
I would like to ask you to post practices you employ in order to have your string operations run smoothly, securely, fast and the re-usability of your code is fairly simple and elegant.
And if you have pattern to it, even better.
Also if you now about any new 1.7 java features that are worth the while please post them here.
What to do when working with very large strings? Break them up?
What to keep in mind when using regex on strings?
How to utilize cache patterns (and which are the best once) when working with loop intensive algorithms?
Are there libraries that have similar functions as grep, ack, diff | spell check | filter curse words (any words) …
When possible you should use StringBuilder , especially for concatenating strings. The performance improvement can be very large.
In a large program the use of s1+s2 is one of the worst and simplest performance hits to cure.
StringBuilder has almost all the features of String. You can extract substrings without copying. When you need a String (e.g. for Pattern/Matcher) you can convert with toString().