-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavastrings.java
62 lines (45 loc) · 1.45 KB
/
Javastrings.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
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
58
59
60
61
62
package basics;
public class Javastrings {
public static void main(String[] args) {
// TODO Auto-generated method stub
String greeting="Hello";
System.out.println(greeting);
//String methods
//1) length()
String txt = "abcdefghijklmnopqrstuvwxyz";
System.out.println("The length of txt string is: "+txt.length());
//2) toLowerCase()
String txt1="Hello World!";
System.out.println(txt1.toLowerCase());
//3) toUpperCase()
System.out.println(txt1.toUpperCase());
//4) indexOf()
String txt2="my name is sunil";
System.out.println(txt2.indexOf('s'));
System.out.println(txt2.indexOf("sunil"));
String txt3="my name is sunil 'sunil' occurs at";
System.out.println(txt3.indexOf("sunil"));
//5) String Concatenation
String fname="sunil";
String lname="shetty";
System.out.println(fname+" "+lname);
System.out.println(fname.concat(lname));
// 6) special character
String txt4="my name is \"sunil\" shetty";
String txt5="my name is \'sunil\' shetty";
String txt6="my name is \\sunil\\ shetty";
System.out.println(txt4);
System.out.println(txt5);
System.out.println(txt6);
String txt7="hello \nmy name \rsunil shetty\t how\bare\byou\nnamasthe\f";
System.out.println(txt7);
int x=10;
int y=20;
int z=x+y;
System.out.println(z);
String x1="10";
String y1="20";
String z1=x1+y1;
System.out.println(z1);
}
}