Strings
This lesson discusses String interview questions in Java.
We'll cover the following...
Question # 1
Can String objects be modified after creation?
No. Strings in Java are immutable and can't be changed once created.
Question # 2
Explain the difference between StringBuilder
and StringBuffer
?
Java provides two utility classes for String manipulations – StringBuffer and StringBuilder.
StringBuffer
and StringBuilder
are mutable classes. StringBuffer operations are thread-safe and synchronized whereas StringBuilder operations are not thread-safe. So in a multi-threaded environment, we should use StringBuffer
but in the single-threaded environment, we should use StringBuilder
.
StringBuilder's ...