stringbuilder methods java code example
Example 1: java string builder
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("string");
System.out.println("String = " + stringBuilder.toString());
Example 2: stringbuffer vs stringbuilder java
The StringBuffer and StringBuilder class both produces mutable string objects.
The main difference between them is that StringBuffer is thread safe;
StringBuilder is not thread safe.
Example 3: what is stringbuilder used for in java
Java StringBuilder class is used to create
mutable (modifiable) string. The Java
StringBuilder class is same as StringBuffer
class except that it is non-synchronized.
StringBuilder()
creates an empty string Builder with the initial capacity of 16.
StringBuilder(String str)
creates a string Builder with the specified string.
StringBuilder(int length)
creates an empty string Builder with the specified capacity as length.
Example 4: stringbuilder in java
Java StringBuilder class is used to create
mutable (modifiable) string. The Java
StringBuilder class is same as StringBuffer
class except that it is non-synchronized.
StringBuilder()
creates an empty string Builder with the initial capacity of 16.
StringBuilder(String str)
creates a string Builder with the specified string.
StringBuilder(int length)
creates an empty string Builder with the specified capacity as length.
Example 5: stringbuilder in java 8
public StringBuilder reverse()