GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing www.tutorialspoint.com — Java StringBuilder Class
Selected Reading
Java StringBuilder ClassStringBuilder Class IntroductionThe Java StringBuilder class is mutable sequence of characters. This provides an API compatible with StringBuffer, but with no guarantee of synchronization. StringBuilder class can be used to replace StringBuffer where single threaded operations are in use. As StringBuffer has overhead of synchronization, StringBuilder acts as a faster alternative of StringBuffer. In case of multi-threaded environment, where we need to synchronized string manipulation operations, StringBuffer is recommanded, otherwise StringBuilder is to be used to improve performance. StringBuilder Class DeclarationFollowing is the declaration for java.lang.StringBuilder class − public final class StringBuilder
extends Object
implements Serializable, CharSequence
StringBuilder Class ConstructorsFollowing is the list of constructors of the StringBuilder class.
StringBuilder Class methodsFollowing is the list of methods of the StringBuilder class. Each method is having multiple examples to demonstrate the functionality of the method.
Methods inheritedThis class inherits methods from the following classes −
Example: Append a Boolean to the StringBuilderThe following example shows the usage of Java StringBuilder append(Boolean b) method. Here, we are instantiating a StringBuilder object "buff" with the string name "tuts". Then, we invoke the append() method using the "buff" object with a boolean argument "true". The return value will be the appended string name "tuts true". Similarly, we demonstrate another case using the string name "abcd" and a boolean argument "false". package com.tutorialspoint;
public class StringBuilderDemo {
public static void main(String[] args) {
StringBuilder stringBuilder = new StringBuilder("tuts ");
System.out.println("builder = " + stringBuilder);
// appends the boolean argument as string to the string stringBuilder
stringBuilder.append(true);
// print the string stringBuilder after appending
System.out.println("After append = " + stringBuilder);
stringBuilder = new StringBuilder("abcd ");
System.out.println("stringBuilder = " + stringBuilder);
// appends the boolean argument as string to the string stringBuilder
stringBuilder.append(false);
// print the string stringBuilder after appending
System.out.println("After append = " + stringBuilder);
}
}
OutputLet us compile and run the above program, this will produce the following result − stringBuilder = tuts After append = tuts true stringBuilder = abcd After append = abcd false Advertisements
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |