In February, I demonstrated the most efficient way I could think of for conditionally building a string. This compared the use of StringBuilder and the ‘+=’ operator whilst checking for null values. The results showed that StringBuilder.append(..) was much faster than using ‘+=’.
Today’s blog covers the much simpler scenario: trying to decide which is the quickest way of of creating a simple string. In order to test this out, I modified the code I’d used last time adding a couple of new methods:
Java tips, observations, bugs and problems from the world of Spring, Weblogic, Oracle, MySQL and many other technologies...
Showing posts with label StringBuilder. Show all posts
Showing posts with label StringBuilder. Show all posts
Monday, 15 August 2011
Wednesday, 18 May 2011
String Formatting
Crusty old Java hacks, myself included, use the StringBuffer class (or StringBuilder) to stitch together strings, but Java 5 added String formatting classes to the API to and a ‘C’ style printf(...) to the System.out class to make life easier.
These newer classes are seemingly often under-used, but pretty straight forward...
These newer classes are seemingly often under-used, but pretty straight forward...
Labels:
Java,
String,
StringBuilder
Friday, 11 February 2011
String and the StringBuilder Usage
One common mistake you often see is code that relies on the repeated concatenation of strings using the String class. String concatenation using the String class okay when all you need to do is concatenate one string to another, but when it comes down to concatenating multiple strings, this method generates serious time penalties.
Labels:
certification,
Java,
String,
StringBuilder
Subscribe to:
Posts (Atom)