String toLowerCase method is used to converts all characters in a given string to lower case. String has 2 toLowerCase methods.
1 2 3 |
public String toLowerCase() public String toLowerCase(Locale locale) |
The first method takes a default Locale for converting the String to lower case, while in the second method we can explicitly give a Locale for the String to convert to lower case.
Lets see an example that covers both these methods.
String toLowerCase example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
package com.kscodes.sampleproject; import java.util.Locale; public class StringToLowerCaseExample { public static void main(String[] args) { String testStr1 = "This is a test String that will be CONVERTED TO LOWERCASE"; System.out.println("Using toLowerCase - Default Locale to convert :: "); System.out.println(testStr1.toLowerCase()); System.out.println("----------------------------------------"); System.out.println("Using toLowerCase(Locale locale) :: "); System.out.println(testStr1.toLowerCase(Locale.ITALIAN)); } } |
Output
1 2 3 4 5 |
Using toLowerCase - Default Locale to convert :: this is a test string that will be converted to lowercase ---------------------------------------- Using toLowerCase(Locale locale) :: this is a test string that will be converted to lowercase |
Please Note:
Before performing any operation on any dynamically generated String, check if the String is not null.
Else a NullPointerException is thrown.
Before performing any operation on any dynamically generated String, check if the String is not null.
Else a NullPointerException is thrown.