java

convert-to-lowercase()

Parameters: String str

The function requires a string input to convert to lowercase.

Returns: The function will return the input string all in lowercase.

This function takes a string of characters as input and converts each uppercase character in the string to its lowercase equivalent, then returns the converted string.

Strings
Functions
Conversion Operations
Easy dificulty

How to Write a Java Function to Convert Text to Lowercase

Hello, fellow programmer! We are glad you're here. This blog post provides a straightforward, step-by-step guide on how to write a functional java code that converts any given string to lowercase. It is written to be easily understood and will help you speed up your learning curve. Enjoy!

Step 1: Understand the problem

The goal of the function convert-to-lowercase is to take an input string and convert all the characters in it to their lowercase version. In Java, we will use the method toLowerCase() which is a part of the String class in Java. This method converts all the characters in the given string to lower case.

String example = "Hello World";
String result = example.toLowerCase();
// Now, result has the value "hello world"

Step 2: Define the function

Start by defining the convert() function. This function will take a string as an input.

public static String convert(String input) {
}

Step 3: Use the toLowerCase() method inside the function

Inside the function use the toLowerCase() method with the input string.

public static String convert(String input) {
    return input.toLowerCase();
}

Step 4: Test the function

It's always good practice to test your functions. Call the function with some test strings to see if it outputs expected results.

public static void main(String[] args) {
    System.out.println(convert("Hello World"));  // prints: hello world
    System.out.println(convert("JAVA is fun!"));  // prints: java is fun!
}

Step 5: Conclusion

This is the final implementation of the convert function. It's a simple function that takes a string input and returns its lowercase version.

public class Main {
    public static String convert(String input) {
        return input.toLowerCase();
    }
    
    public static void main(String[] args) {
        System.out.println(convert("Hello World"));
        System.out.println(convert("JAVA is Fun!"));
    }
}

The code has been tested and is fully functional. It can convert any string to lowercase, which seems to meet the requirements.

Learn function in:

Character Case Conversion

This function converts any uppercase characters in a string to lowercase.

Learn more

Mathematical principle

The function uses the ASCII value differences between uppercase and lowercase characters. In ASCII, the difference between an uppercase character and its lowercase equivalent is 32. Thus, you can change character c to lowercase by performing c = c + 32 if c is an uppercase letter.

Learn more