Groovy - String toUpperCase() method
toUpperCase() method converts all characters to upper case.
Syntax
String toUpperCase()
Parameters
NA
Return Value
It returns the modified string in upper case.
Example - Converting a String to Upper Case
Following is an example of the usage of toUpperCase() method.
Example.groovy
class Example {
static void main(String[] args) {
// converts all lower case letters in to upper case letters
String str1 = "This is TutorialsPoint";
println("string value = " + str1.toUpperCase());
str1 = "www.tutorialspoint.com";
println("string value = " + str1.toUpperCase());
}
}
Output
When we run the above program, we will get the following result −
string value = THIS IS TUTORIALSPOINT string value = WWW.TUTORIALSPOINT.COM
Example - Converting a String to Upper Case Using Locale
Following is an example of the usage of toUpperCase() method. Here we're passing a locale parameter −
Example.groovy
class Example {
static void main(String[] args) {
String str1 = "This is TutorialsPoint";
// using the default system Locale
Locale defaultLocale = Locale.getDefault();
// converts all lower case letters in to upper case letters
println("string value = " + str1.toUpperCase(defaultLocale));
str1 = "www.tutorialspoint.com";
println("string value = " + str1.toUpperCase(defaultLocale));
}
}
Output
When we run the above program, we will get the following result −
string value = THIS IS TUTORIALSPOINT string value = WWW.TUTORIALSPOINT.COM
Example - Converting a String containing non-alphabetical characters to Upper Case
Following is an example of the usage of toUpperCase() method.
Example.groovy
class Example {
static void main(String[] args) {
String s = "Welcome to @!! Tutorials point 77!!";
println("The given string is: " + s);
String toUpper = s.toUpperCase();
println("String after conversion is: " + toUpper);
}
}
Output
When we run the above program, we will get the following result −
The given string is: Welcome to @!! Tutorials point 77!! String after conversion is: WELCOME TO @!! TUTORIALS POINT 77!!
groovy_strings.htm
Advertisements