Page 248 - Computer science 868 Class 12
P. 248
Note: If the character is not found, the method will return -1.
5. int lastIndexOf(char ch): This method returns the index value of the last existence of the character ch present in
the string of the current String object. It returns an integer type of value.
String st = "We study in class 12";
int v = st.lastIndexOf('s');
System.out.println("The index value is :" +v);
Output:
The index value is: 16
6. String toLowerCase(): This method converts the string of the current String object to small letters. It returns a
String.
Note: If the Stringobject contains any small letters or digits or special characters, then there will be no
change.
String st = "We study in class 12";
String convertstr = st.toLowerCase();
System.out.println("The converted string is :" +sonvertstr);
Output:
The converted string is: we study in class 12
7. String toUpperCase(): This method converts the string of the current String object to capital letters. It returns a
String.
Note: If the string contains any capital letters or digits or special characters, then there will be no change.
String st = "We study in class 12";
String convertstr = st.toUpperCase();
System.out.println("The converted string is :" +convertstr);
Output:
The converted string is: WE STUDY IN CLASS 12
8. String concat(String st): This method joins two strings together. The string of the current String object whose
method is called and the string in the parameter are the two strings that are joined. This method returns a string.
String st1 = "Computer";
String st2 = "Desktop";
String joinst = st1.concat(st2); // We can also use "+" operator to concatenate
// String joinst = st1 + st2;
System.out.println("The joined string is :" +joinst);
Output:
The joined string is: ComputerDesktop
9. String substring(int index): This method is used for extracting all the characters from the index position till the end
of the string. It returns a String.
String st = "We study in class 12";
String extractst = st.substring(3);
System.out.println("The Extracted string is :" +extractst);
Output:
The Extracted string is: study in class 12
246246 Touchpad Computer Science-XII

