Advertisement
public StringBuilder()
Creates a StringBuilder object with initial capacity of 16 characters.public StringBuilder(String str)
Creates a StringBuilder object using a String str.public StringBuilder(int capacity)
Creates a StringBuilder object with a defined capacity of characters.
// Java - Example of StringBuilder class
class StringBuilderEx
{
public static void main(String... ar)
{
//Creating an empty StringBuilder object.
StringBuilder sb= new StringBuilder();
//Printing the empty StringBuilder object
System.out.println("Original StringBuilder value : "+ sb);
//Appending a new String, Blue, to the StringBuilder object
sb.append("Blue");
//Appending a new String, Budgie, to the StringBuilder object
sb.append("Budgie");
//Printing the modified StringBuilder object
System.out.println("Modified StringBuilder value : "+ sb);
}
}
Original StringBuilder value is :
Modified StringBuilder value is : BlueBudgie
Advertisement
// Java - Example of StringBuilder class
class StringBuilderEx
{
public static void main(String... ar)
{
//Creating a StringBuilder object
StringBuilder sb= new StringBuilder("Blue");
//Printing the StringBuilder object
System.out.println("Original StringBuilder value : "+ sb);
//Appending a new String to the StringBuilder object
sb.append("Sky");
//Printing the modified value of the StringBuilder object
System.out.println("Modified StringBuilder value : "+ sb);
}
}
Original StringBuilder value : Blue
Modified StringBuilder value : BlueSky
// Java - Example of StringBuilder class
class A
{
public static void main(String... ar()
{
//Creating a StringBuilder object
StringBuilder sb= new StringBuilder("Hello");
//Printing the StringBuilder object
System.out.println("Original StringBuilder value : "+ sb);
//Reversing the original string within StringBuilder object
sb.reverse();
//Printing the modified StringBuilder object
System.out.println("Modified reverse StringBuilder value : "+ sb);
}
Original StringBuffer string value : Hello
Modified reverse StringBuilder value : olleh
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement