StringUtils lowerCase() Method

StringUtils lowerCase() Method | In this blog, we will discuss the lowerCase() method of the StringUtils class. It is a static method that converts the string to a lower case and if the string is null then this method returns null. There are two variations in the method one just accepts the string and the other accepts string and locale.

StringUtils.lowerCase() Method

The syntax for the lowerCase method is as follows:-

  • public static String lowerCase(final String str):- It converts a String to lowercase as per the current locale.
  • public static String lowerCase(final String str, final Locale locale):- It converts a String to lowercase as per the given locale.

Parameters:
str: the string which needs to be converted to lowercase.
locale: this is a case transformation rule.
Return type:- String
Return value:- string in the lowercase.

Java StringUtils lowerCase() Method

Let us see an example of the default lowercase method that is lowerCase(String str). When the string variable is referring to the null value then StringUtils.lowerCase() method returns the null itself. If the string variable contains an empty string then the StringUtils.lowerCase() method returns an empty string.

import org.apache.commons.lang3.StringUtils;

public class Main {

    public static void main(String[] args) {
        String string = "Know Program";
        System.out.println("After conversion: " + StringUtils.lowerCase(string));

        string = "";
        System.out.println("After conversion: " + StringUtils.lowerCase(string));

        string = null;
        System.out.println("After conversion: " + StringUtils.lowerCase(string));
    }
}

Output:-

After conversion: know program
After conversion:
After conversion: null

StringUtils lowerCase() Example

Let us see an example of the StringUtils lowerCase() method using locale.

import java.util.Locale;

import org.apache.commons.lang3.StringUtils;

public class Main {

    public static void main(String[] args) {
        String string = "ΙΧΘΥΣ";
        System.out.println(StringUtils.lowerCase(string, Locale.ENGLISH));
        System.out.println(StringUtils.lowerCase(string, Locale.GERMAN));
        System.out.println(StringUtils.lowerCase(string, Locale.FRANCE));
    }
}

Output:-

ιχθυς
ιχθυς
ιχθυς

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *