Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Java's character and assorted string classes support text-processing

Explore Character, String, StringBuffer, and StringTokenizer

  • Print
  • Feedback

Page 8 of 10

Argentina not found
Argentina found


The StringBuffer class

String is not always the best choice for representing strings in a program. The reason: Its immutability causes String methods, such as substring(int beginIndex, int endIndex), to create new String objects, rather than modify the original String objects. In many situations, that leads to unreferenced Strings that become eligible for garbage collection. When many unreferenced Strings are created within a long loop, overall heap memory reduces, and the garbage collector might need to perform many collections, which can affect a program's performance, as the following code demonstrates:

  • Print
  • Feedback

Resources