Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Java 9 questions

String, StringBuffer, and StringBuilder

Differentiate immutable String from mutable StringBuffer and StringBuilder. Learn performance, memory allocation, and thread safety.

More Java
Interview questions 1–9 of 9
1

What is String immutability in Java?

String immutability means once a String object is created, it cannot be changed. If you modify a string, a new...

Read answer →
2

What is the difference between String, StringBuffer, and StringBuilder?

FeatureStringStringBufferStringBuilderMutabilityImmutableMutableMutableThread-SafeYes (immutable)Yes (synchron...

Read answer →
3

What is String Pool (String Constant Pool) in Java?

String Pool is a special memory region where String literals are stored. Java checks if a String already exist...

Read answer →
4

How do you compare Strings in Java? Explain ==, equals(), and compareTo().

String s1 = "Hello"; String s2 = "Hello"; String s3 = new String("Hello"); System.out.println(s1 == s2);...

Read answer →
5

What are important String methods in Java?

Java String class provides many useful methods for string manipulation, searching, and transformation.String s...

Read answer →
6

What are different ways to concatenate strings in Java?

String result = "Hello" + " " + "World"; String s1 = "Hello".concat(" World"); StringBuilder sb = new StringBu...

Read answer →
7

What are important StringBuffer methods?

StringBuffer sb = new StringBuffer("Hello"); sb.append(" World"); sb.insert(5, " World"); sb.delete(6, 11); sb...

Read answer →
8

Why is StringBuilder faster than StringBuffer?

StringBuilder is faster because it does not use synchronization. StringBuffer methods are synchronized for thr...

Read answer →
9

What is String interning and the intern() method?

String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2); // true String s3 = new String("Hello...

Read answer →