Page 420 - CA_Blue( J )_Class10
P. 420
16.3.6 The toUpperCase() Method
The toUpperCase() method converts the String to capital letters. It returns a String value. The syntax to use the
toUpperCase() method is:
String <variable> = <String_Object>.toUpperCase();
For example:
String str= "KOLkatA – 700114";
String changestr= str.toUpperCase();
System.out.println("The converted string is: " +changestr);
You will get the following output:
The converted string is: KOLKATA – 700114
Note: If the string contains any capital letters or digits or special characters, then there will be no
change.
16.3.7 The concat() Method
The concat() method combines two strings together. The String object through which the concat() method is called
and the String passed in the parameter are the two strings that are combined. The process of combining two strings is
known as concatenation. The concate() method returns a String value after concatenating both the strings. The syntax
to use the concat() method is:
String <variable> = <String_Object>.concat(String str);
For example:
String str1= "Kolkata-";
String str2="700114";
String joinstr= str1.concat(str2);
System.out.println("The joined string is: " +joinstr);
You will get the following output:
The joined string is: Kolkata–700114
We can also use the “+” operator to concatenate two strings. For example:
String str1= "Kolkata-";
String str2="700114";
String joinstr= str1 + str2;
System.out.println("The joined string is: " +joinstr);
You will get the following output:
The joined string is: Kolkata–700114
16.3.8 The substring() Method
A substring is a part of a string. The substring() method is used for extracting all the characters from the index position
till the end of the string. It returns a String value. The syntax to use the substring() method is:
String <variable> = <String_Object>.substring(int index);
For example:
String str= "Kolkata-700114";
String extractstr= str.substring(8);
System.out.println("The extracted string is: " +extractstr);
You will get the following output:
The extracted string is: 700114
The substring() method also has an overloaded method which takes starting index from where the substring started
and the ending index upto which the substring should be taken as parameters. The substring(beginIndex, endIndex)
418418 Touchpad Computer Applications-X

