-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringbuilder.java
More file actions
55 lines (40 loc) · 1.16 KB
/
Copy pathStringbuilder.java
File metadata and controls
55 lines (40 loc) · 1.16 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
49
50
51
52
53
54
55
public class Stringbuilder {
public static void main(String[] args) {
// TODO Auto-generated method stub
// StringBuilder sb=new StringBuilder("Tony");
//sb naam ka string of type stringbuilder
// System.out.println(sb);
// System.out.println(sb.charAt(0));
//set char at index
// sb.setCharAt(0, 'P'); //only make changes not println
// System.out.println(sb);
//insert string
// sb.insert(2, 'n');
//// System.out.println(sb);
////
//// //delete the extra n
//// sb.delete(2, 3); //bas 2 tk jayega
//// System.out.println(sb);
//
// sb.delete(2, 4);
// System.out.println(sb);
//performing operations with hello
StringBuilder sb=new StringBuilder("h");
sb.append("e");
sb.append("l");
sb.append("l");
sb.append("o"); //using append we reduce tc and also changes occur at the string
System.out.println(sb);
//reversing a string
for(int i=0;i<sb.length()/2;i++)
{
int front=i;
int back=sb.length()-i-1; //piche se
char frontchar=sb.charAt(front) ; //front char
char backchar=sb.charAt(back);
sb.setCharAt(front, backchar);
sb.setCharAt(back, frontchar);
}
System.out.println(sb);
}
}