Java – String vs StringBuffer

This article shows the difference in time taken for similar operations on a String object and StringBuffer object. String being an immutable class, it instantiates a new object each time an operation is performed on it StringBuffer being a mutable class, the overhead of object instantiation during operations is removed. Hence, the time taken for …

Read more

How to clear / delete the content of StringBuffer()

The StringBuffer is always been using for the String concatenation. However this class didn’t provide a method to clear the existing content. Why there are no clear() function? You can use the delete(int start, int end) as dirty trick : sb.delete(0, sb.length()); 1 . Example package com.mkyong.io; public class App{ public static void main (String …

Read more