How to convert all char in string lower case in java Program

public class StringLowerExample {
  public static void main(String args[]) {
    String s1 = "TechSarvam by Rajendrasarvam HELLO stRIng";
    String s1lower = s1.toLowerCase();
    System.out.println(s1lower);
  }
}

Step-by-Step Breakdown:

1. Class and Method Declaration:

public class StringLowerExample 

{

    public static void main(String args[]) 

     {

  • The program defines a class StringLowerExample.
  • The main method is the entry point of the program where execution starts.

2. String Initialization:

String s1 = “TechSarvam by Rajendrasarvam HELLO stRIng”;

  • A string variable s1 is declared and initialized with the value  “TechSarvam by Rajendrasarvam HELLO stRIng”.
  • This string contains a mix of uppercase and lowercase letters.

3. Using toLowerCase() Method:

String s1lower = s1.toLowerCase();

  • toLowerCase() method is applied on the string s1. This method converts all the characters of the string s1 into lowercase.
  • toLowerCase() returns a new string with all its characters converted to lowercase, and the result is assigned to the s1lower variable.

The string s1lower after the toLowerCase() operation will be:

“TechSarvam by Rajendrasarvam hello string”.

4. Printing the Result:

System.out.println(s1lower);

This will print the string stored in s1lower, which is the original string in lowercase.

Program Output

This program prints the output string in which the characters of the original string appear in all lowercase format.

TechSarvam by Rajendrasarvam hello string

Summary

  • The toLowerCase() method is used to convert all the characters in a string to lowercase.
  • The input string s1 consists of a combination of uppercase and lowercase letters; all characters of the string will be converted into lowercase after applying toLowerCase() method.
  • A whole string may be converted into lowercase through the following code example.

Leave a Comment

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