Convert the given string into lowercase in Java


The string in converts all characters of the string into lower case letter. The string to be any length and calculate its length. scan string character by character and keep checking the index. If a character in an index is in upper case, then add 32 to convert it in lower case.

Source Code

public class lowercase {
    public static void main(String args[]) {
        //Program to Convert string to LowerCase
        StringBuilder a = new StringBuilder("ABCD");
        System.out.println("Original Input : "+a);
        for(int i=0;i<a.length();i++)//97-122
        {
            if (a.charAt(i) >= 65 && a.charAt(i) <= 90) {
                int c=(int)a.charAt(i)+32;//65+32=97  66+32=98  67+32=99 68+32=100
                a.setCharAt(i,(char)c);//abcd
            }
        }
        System.out.println("Lowercase Output: "+a);
 
 
    }
}
 

Output

Original Input : ABCD
Lowercase Output: abcd
To download raw file Click Here
`

Basic Programs