-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringBuffer1.java
More file actions
26 lines (19 loc) · 855 Bytes
/
Copy pathStringBuffer1.java
File metadata and controls
26 lines (19 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// StringBuffer stores String(in heap), it is mutable
public class StringBuffer1 {
public static void main(String[] args) {
StringBuffer sb= new StringBuffer("Java");
System.out.println(sb);
sb.append(" is fun"); // as it is mutable, the String value will be changed
System.out.println(sb);
sb= sb.append(" to learn");
System.out.println(sb); // Java is fun to learn
sb= new StringBuffer("and code"); // object reassign
System.out.println(sb); //and code
final StringBuffer sb1= new StringBuffer("Python");
System.out.println(sb1);
sb1.append(" is easy");
System.out.println(sb1);
/*sb1= sb1.append(" is dynamic"); //ERROR- cannot assign value to final variable
System.out.println(sb1);*/
}
}