Groovy Operators

Control Statements

Groovy File Handling

Groovy Error & Exceptions

Groovy Multithreading

Groovy Synchronization

Groovy - String toLowerCase() method



toLowerCase() method converts all characters to lower case.

Syntax

String toLowerCase()

Parameters

NA

Return Value

It returns the modified string in lower case.

Example - Converting a String to Lower Case

Following is an example of the usage of toLowerCase() method.

Example.groovy

class Example { 
   static void main(String[] args) { 
      // converts all lower case letters in to lower case letters
      String str1 = "This is TutorialsPoint";
      println("string value = " + str1.toLowerCase());    
      str1 = "www.tutorialspoint.com";
      println("string value = " + str1.toLowerCase());      
   } 
}

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 Lower Case Using Locale

Following is an example of the usage of toLowerCase() 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 lower case letters
      println("string value = " + str1.toLowerCase(defaultLocale));    
      str1 = "www.tutorialspoint.com";
      println("string value = " + str1.toLowerCase(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 Lower Case

Following is an example of the usage of toLowerCase() method.

Example.groovy

class Example { 
   static void main(String[] args) { 
      String s = "Welcome to @!! Tutorials point 77!!";
      println("The given string  is: " + s);
      String toLower = s.toLowerCase();
      println("String after conversion is: " + toLower);     
   } 
}

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