Convert String to Lowercase in Java Without Using String Library

Learn how to convert a string to lowercase in Java without using built-in String methods. This blog explains the ASCII-based logic with examples, a Java program, and practice challenges.

Convert String to Lowercase in Java Without Using String Library

Converting a string to lowercase without using built-in String methods helps beginners understand how characters are represented internally and how ASCII values work.

In this blog, you will learn:

Understanding ASCII Values

In ASCII:

The difference between uppercase and lowercase letters is 32.

How the Logic Works

To convert a string to lowercase manually:

  1. Traverse each character of the string.
  2. If the character is between 'A' and 'Z', add 32.
  3. Leave other characters unchanged.

Example

Input: "Java PROGRAMMING 101"

Output: "java programming 101"

Java Program to Convert String to Lowercase


import java.util.Scanner;

public class StringToLowercase {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a string: ");
        String input = sc.nextLine();

        String result = "";

        for (int i = 0; i < input.length(); i++) {
            char ch = input.charAt(i);

            if (ch >= 'A' && ch <= 'Z') {
                ch = (char) (ch + 32);
            }

            result = result + ch;
        }

        System.out.println("Lowercase String: " + result);
    }
}

Sample Output


Enter a string: HELLO World
Lowercase String: hello world

Practice Challenges

  1. Convert a string to uppercase without using String library methods.
  2. Toggle the case of each character in a string.
  3. Count uppercase and lowercase characters in a string.

Manual case conversion builds a strong foundation in character handling and ASCII logic. These concepts are commonly tested in interviews and competitive programming.