What are differences between String, StringBuffer, and StringBuilder in Java?
In Java, strings are essential for handling text data. Java provides three main classes for working with strings: String, StringBuffer, and StringBuilder. Each has distinct features and use cases. 1. String: 2. StringBuffer: 3. StringBuilder: Key Differences: Feature String StringBuffer StringBuilder Mutability Immutable Mutable Mutable Thread-Safe Yes Yes No Performance Slower (due to immutability) Slower (due to synchronization) Faster (no synchronization) Use Case When immutability is required. Multi-threaded environments. Single-threaded…