-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuilderString.java
32 lines (25 loc) · 939 Bytes
/
BuilderString.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
public class BuilderString {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder("TomAndJerry");
System.out.println(sb);
//this charAt() helps to give only pointed letter
System.out.println(sb.charAt(0));
//to change the letter
//sb.setCharAt(index, ch);<-syntax
sb.setCharAt(0, 'B');
System.out.println(sb);//in upper line it has changed the value so thats why sb is uesed here
//insert is used to insert letter in the word
sb.insert(2, 'o');
System.out.println(sb);
//.delete is used to delete form index number to wanted number
sb.delete(2, 3);
System.out.println(sb);
//append meaning adding letter at last
sb.append('N');
sb.append('i');
sb.append('n');
sb.append('j');
sb.append('a');
System.out.println(sb);
}
}