What is string buffer in java?
Before going to learn about string buffer know about strings.
- The main difference between string and string buffer is string buffer is mutable whereas string is Immutable.
- It means any value assigned to stringBuffer it can be modified in entire execution program
---> StringBuffer is thread-safe i.e., multiple threads can't access simultaneously.So we have to access in an order.It means StringBuffer is Synchronized.
StringBufferDemo program:
public class StringDemo {
public static void main(String[] args) {
String a = "one";
a.concat("two");
System.out.println(a);
StringBuffer sb = new StringBuffer("three");
sb.append("four");
System.out.println(sb);
}
}
Output:
string buffer in java
Please comment below to feedback or ask questions.
No comments:
Post a Comment
Please comment below to feedback or ask questions.