- Mutable sequence of characters.
Unlike, String which is immutable (cannot be changed).
Benefits:
1. Allows you to append, insert or delete characters efficiently without creating a new object each time.
CODE:
public class Main {
public static void main(String str[]) {
StringBuilder sb = new StringBuilder();
sb.append("Hello");
sb.append(" World");
System.out.println(sb.toString()); // Output: Hello World
}
}
No comments:
Post a Comment