-
Notifications
You must be signed in to change notification settings - Fork 0
/
str.java
47 lines (31 loc) · 1.43 KB
/
str.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
public class str
{
public static void main(String args[]){
char array[]={'h','e','l','l','o'};
String s=new String(array); //converts the array of characters into a single string
System.out.println(s);
String s1="WOrld";
System.out.println(s1.charAt(3)); //returns character at the particular index
System.out.println(s1.toLowerCase()); //converts all chars to lower case
System.out.println(s1.toUpperCase()); //converts all chars to upper case
System.out.println(s1.length()); //returns length of the string
String y="IT ";
System.out.println(y.concat(s1)); // concates the second string to the first one.
String s2=" hello world ";
System.out.println(s2.contains(s1)); //checks if s2 contains s1 in it
System.out.println(s2.compareToIgnoreCase(s1)); // compares s1 and s2 and returns 0 if not equal
System.out.println(s2.replace('l','c')); //used to replace the all the occurences of the first character with the second character
System.out.println(s2.trim()); //remove the trailing and the leading space.
System.out.println(s2.endsWith("w")); //returns true if the string ends with the given char or the substring
String c="Abc";
byte[] b=c.getBytes(); //returns ascii value of the string chars in a byte array
for(int i=0;i<b.length;i++){
System.out.println(b[i]);
}
String s3="hello#world%welcome";
String[] as=s3.split('#');
for (String x:as){
System.out.println(x);
}
}
}