-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathFirstProgram.java
More file actions
48 lines (40 loc) · 1.47 KB
/
FirstProgram.java
File metadata and controls
48 lines (40 loc) · 1.47 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 StringBuilders;
public class FirstProgram {
public static void main(String[] args) {
// declare string builder
StringBuilder sb = new StringBuilder("Prity");
System.out.println(sb);
//get a character at any index using .charAt() function
System.out.println(sb.charAt(0));
//set a character at any index using .setCharAt() function
sb.setCharAt(0, 'K');
System.out.println(sb);
//insert some charecter in the string at any index using .insert(indexNumber, insertedCharacter) function
sb.insert(0, 'A');
System.out.println(sb);
// delete the character in the string at any index using .delete(startIndexNumber, endIndexNumber)function
// first value : jhan se delete start karna h
// second value : jhan tak delete karna hai
sb.delete(0, 1);
System.out.println(sb);
//add some character in the string at ending position using .append()function
// ya ise append bhi kahte hain means add something at the end
sb.append("S"); //str = str + "S";
sb.append("i"); //str = str + "i";
sb.append("n"); //str = str + "n";
sb.append("g"); //str = str + "g";
sb.append("h"); //str = str + "h";
System.out.println(sb);
// find length of string using .length() function
System.out.println(sb.length());
}
}
//output
/*
Prity
P
Krity
AKrity
Krity
KritySingh
10 */