-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringbuilder.java
More file actions
49 lines (36 loc) · 1.13 KB
/
Stringbuilder.java
File metadata and controls
49 lines (36 loc) · 1.13 KB
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
38
39
40
41
42
43
44
45
46
47
48
package ApnaCollege;
public class Stringbuilder {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder("hellllooo");
//1 method to reverse
// sb.reverse();
// System.out.println(sb);
//2nd method to reverse
for (int i = 0; i < sb.length() / 2; i++) {
int front = i;
int back = sb.length() - 1 - i; // 9 - 1 - 0 = 8
char frontchar = sb.charAt(front);
char backchar = sb.charAt(back);
sb.setCharAt(front, backchar);
sb.setCharAt(back, frontchar);
}
System.out.println(sb);
}
}
// sb.append("e");
// sb.append("h");
// sb.append("e");
// System.out.println(sb);
//// //char at 0 index
//// System.out.println(sb.charAt(0)); // print the character at 0 index
////
//// sb.setCharAt(0,'M');
//// System.out.println(sb);
//
// //insert character At any index
// sb.insert(2,'a');
// System.out.println(sb);
//
// //delete the extra a in Amaan
// sb.delete(2,3);
// System.out.println(sb);