-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringBufferdemo.java
37 lines (27 loc) · 1.05 KB
/
StringBufferdemo.java
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
27
28
29
30
31
32
33
34
35
36
37
//StringBuffer is mutable, with initial capacity 16,
//growable in runtime as per the string size
public class StringBufferdemo {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("Codefrombasics");
System.out.println(sb.capacity());
System.out.println("Before adding Azure Training " + sb);
sb.append(" Azure Training ");
System.out.println("After adding Azure Training " + sb);
System.out.println("capcity " + sb.capacity());
System.out.println("Length " + sb.length());
sb.insert(1, "Java");
System.out.println(sb);
StringBuilder sbuild = new StringBuilder();
String number = "7897897898";
String mask = "xxxxxx$$$$";
for (int i = 0; i < number.length(); i++) {
char c = mask.charAt(i);
if (c == 'x') {
sbuild.append(c);
} else if (c == '$') {
sbuild.append(number.charAt(i));
}
}
System.out.println(sbuild.toString());
}
}