-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTut5.java
More file actions
57 lines (52 loc) · 1.45 KB
/
Tut5.java
File metadata and controls
57 lines (52 loc) · 1.45 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
56
57
package tutorial;
//String
public class Tut5 {
public static void main(String[] args) {
// Declaring String can be declared in 2 ways
// 1st way
String firstway = "Prathamesh";
// 2nd way
String secondway = new String("Dhande");
// Note : this strings are note changeable means Immutable
System.out.println(firstway + secondway); // This is String concatenation
// Methods of String
System.out.println("CharAt 1 :" + firstway.charAt(1));
System.out.println(firstway.concat("Prashant")); // another way of concatenation;
System.out.println(firstway.length()); // length of a String
System.out.println(firstway.toLowerCase());
System.out.println(firstway.toUpperCase());
System.out.println(" kyu".trim());
System.out.println(firstway.substring(1, 7));
System.out.println(firstway.repeat(2));
System.out.println(firstway.contains("t"));
System.out.println(firstway.replace("t", "z"));
System.out.println(firstway); // original string is not changed
System.out.println(firstway.compareTo("Dhande"));
System.out.println(firstway.equals("Prathamesh"));
System.out.println(firstway.equals("Prathame"));
System.out.println(firstway.equalsIgnoreCase("prathamesh"));
System.out.println(firstway.startsWith("P"));
System.out.println(firstway.indexOf("r"));
}
}
/*
* Output:
* PrathameshDhande
CharAt 1 :r
PrathameshPrashant
10
prathamesh
PRATHAMESH
kyu
ratham
PrathameshPrathamesh
true
Prazhamesh
Prathamesh
12
true
false
true
true
1
*/