Pages

Wednesday, October 1, 2025

What is a StringBuilder?

 - 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

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...