Description
public StringBuilder append(boolean b)
: This method appends the string representation of the boolean value(provided as an argument to this method, during call) to the StringBuilder
sequence.
Example
This example shows two ways to append a boolean value to the StringBuilder. We can append the value directly by using boolean literal or by using boolean variable. In both the cases, the string representation of boolean values “true” or “false” would be append to the StringBuilder. Here is the complete code:
import java.lang.StringBuilder; class StringBuilderAppend{ public static void main(String[] args) { StringBuilder sb = new StringBuilder("My Initial String"); // Appending boolean value sb.append(true); // Initializing a boolean variable boolean bvar = false; // Appending Boolean variable sb.append(bvar); // Display StringBuilder System.out.println(sb); } }
Output:
My Initial Stringtruefalse
In the above example we have appended a boolean literal and a boolean variable. In both the cases we have used the method StringBuilder.append(boolean b). As you can see, the output is having the String representation of boolean values appended to the String initialized by StringBuilder
instance.
Leave a Reply