-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringDemo.java
More file actions
33 lines (24 loc) · 847 Bytes
/
Copy pathStringDemo.java
File metadata and controls
33 lines (24 loc) · 847 Bytes
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
package strings;
public class StringDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s ="This class is to explain about strings";
//To find the index positions
System.out.println(s.indexOf("s"));
System.out.println(s.indexOf("s", s.indexOf("s", s.indexOf("s"))+1));
System.out.println(s.indexOf("s", s.indexOf("s",s.indexOf("s", s.indexOf("s", s.indexOf("s"))+1)+1)));
//To find the character at the given index
System.out.println(s.charAt(5));
//Reverse a string using inbuilt function
StringBuilder strBd=new StringBuilder();
strBd.append(s);
System.out.println(strBd.reverse());
//Reverse using for loop
String rev="";
for(int i=s.length()-1;i>=0;i--)
{
rev=rev+s.charAt(i);
}
System.out.println(rev);
}
}