User Oleksandr Miadelets
Oleksandr Miadelets
Head of Developers Team at CodeGym

String toLowerCase() Method in Java

Published in the Java Developer group

What is the toLowerCase() Method?

Java facilitates with a built-in method to convert the String contents to lower case using the toLowerCase() method.

Method Header


public String toLowerCase()

Method Arguments

Not any. [It operates perfectly fine without arguments. However, it does take an area-based parameter for punctuation rules called Locale, which is out of the scope of this post.]

Return Type

A String in lower case.

Example 1

Let’s have a look at an example to understand this better.

public class ToLowerCase {
    public static void main(String[] args) {
        String myName = "Lubaina Khan";
        System.out.println("How do you spell your name? " + myName);
        // using toLowerCase() method
        System.out.println("May I have a lower case version? " + myName.toLowerCase());
    }
}

Output

How do you spell your name? Lubaina Khan May I have a lower case version? lubaina khan

Example 2


public class ToLowerCase {

	public static void main(String[] args) {

		String date = java.util.Calendar.getInstance().getTime().toString();
		System.out.println("System Date : " + date);
		// using toLowerCase() method
		System.out.println("[lower case] : " + date.toLowerCase() + "\n");

		String paragraph = "This constantly evolving world still needs Java.";
		System.out.println("Original Paragraph: " + paragraph);
		// using toLowerCase() method
		System.out.println("[lower case] : " + paragraph.toLowerCase() + "\n");

		String punctuationPara = "Would you like to have some tea, Miss Peterson?";
		System.out.println("Punctuation Paragraph: " + punctuationPara);
		// using toLowerCase() method
		System.out.println("[lower case] : " + punctuationPara.toLowerCase() + "\n");
	}
}

Output

System Date : Sat Jul 24 08:36:01 PKT 2021 [lower case] : sat jul 24 08:36:01 pkt 2021 Original Paragraph: This constantly evolving world still needs Java. [lower case] : this constantly evolving world still needs java. Punctuation Paragraph: Would you like to have some tea, Miss Peterson? [lower case] : would you like to have some tea, miss peterson?
String toLowerCase() Method in Java - 1

Conclusion

That was a quick demonstration of using the String toLowerCase() method in Java. We encourage you to learn by practice. Feel free to replug in case of any ambiguity.
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION