What is StringUtils.toRootLowerCase in Java?
toRootLowerCase() is a StringUtils class that is used to convert the given string to lowercase using the Locale.ROOT locale in a null-safe manner.
What is Locale.ROOT?
Locale.ROOT is a handy constant for the root locale. The root locale is the one with empty ("") strings for language, country, and variant attributes that define a Locale. This is the foundation locale for all locales, and it is utilized as the language/country-neutral locale for actions that are sensitive to locales.
How to import StringUtils
The definition of StringUtils can be found in the Apache Commons Lang package, which we can add to the Maven project by adding the following dependency to the pom.xml file.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
For other versions of the
commons-langpackage, refer to the Maven Repository.
You can import the StringUtils class as follows.
import org.apache.commons.lang3.StringUtils;
Syntax
public static String toRootLowerCase(final String source)
Parameters
final String source: The string to convert.
Return value
This method returns a lower cased string.
Code
import org.apache.commons.lang3.StringUtils;public class Main {public static void main(String[] args) {// Example 1String s = "HellO-EDUcative";System.out.printf("The output of StringUtils.toRootLowerCase() for the string - '%s' is %s", s, StringUtils.toRootLowerCase(s));System.out.println();// Example 2s = "";System.out.printf("The output of StringUtils.toRootLowerCase() for the string - '%s' is %s", s, StringUtils.toRootLowerCase(s));System.out.println();// Example 3s = null;System.out.printf("The output of StringUtils.toRootLowerCase() for the string - '%s' is %s", s, StringUtils.toRootLowerCase(s));System.out.println();}}
Example 1
string = "HellO-EDUcative"locale = english
The method returns hello-educative where the string is converted to lowercase.
Example 2
string = ""locale = english
The method returns `` as the input string is empty.
Example 3
string = nulllocale = english
The method returns null as the input string is null.
Output
The output of the code will be as follows.
The output of StringUtils.toRootLowerCase() for the string - 'HellO-EDUcative' is hello-educative
The output of StringUtils.toRootLowerCase() for the string - '' is
The output of StringUtils.toRootLowerCase() for the string - 'null' is null
Free Resources
- undefined by undefined