Tagged: #Stringbuffer

Java – Convert List to comma-separated String

This tutorial shows several ways for converting a List to a comma-separated String in Java. 1- Java 7 The traditional way of converting a List to a comma-separated String in Java 7 and older versions is through using StringBuilder as the following:

2- Java 8 In Java 8, there are 2 conversion ways. 2.1. String.join() The most common way is...

StringBuilder VS StringBuffer

Since String is immutable, it is very costly to use it when constructing a dynamic character string due to the fact that a new memory location will be allocated at each assignment or modification. Since its first release, Java supports a mutable class called StringBuffer which constructs dynamic character strings through allocating just 1 memory location, this saves a lot...