Convert Unicode Code Point to Lowercase

JavaJavaBeginner
Practice Now

Introduction

In this lab, we will learn about the toLowerCase(int codePoint) method in Java. It is a method of the Character class and is used to convert the specified Unicode code point character argument to its lowercase equivalent. The toLowerCase() method uses the case mapping information provided by the Unicode Data file.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL java(("`Java`")) -.-> java/ProgrammingTechniquesGroup(["`Programming Techniques`"]) java(("`Java`")) -.-> java/ObjectOrientedandAdvancedConceptsGroup(["`Object-Oriented and Advanced Concepts`"]) java(("`Java`")) -.-> java/BasicSyntaxGroup(["`Basic Syntax`"]) java(("`Java`")) -.-> java/DataStructuresGroup(["`Data Structures`"]) java(("`Java`")) -.-> java/StringManipulationGroup(["`String Manipulation`"]) java(("`Java`")) -.-> java/SystemandDataProcessingGroup(["`System and Data Processing`"]) java/ProgrammingTechniquesGroup -.-> java/scope("`Scope`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/classes_objects("`Classes/Objects`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/class_methods("`Class Methods`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/modifiers("`Modifiers`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/oop("`OOP`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/user_input("`User Input`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/wrapper_classes("`Wrapper Classes`") java/BasicSyntaxGroup -.-> java/identifier("`Identifier`") java/DataStructuresGroup -.-> java/arrays("`Arrays`") java/BasicSyntaxGroup -.-> java/data_types("`Data Types`") java/BasicSyntaxGroup -.-> java/for_loop("`For Loop`") java/BasicSyntaxGroup -.-> java/operators("`Operators`") java/BasicSyntaxGroup -.-> java/output("`Output`") java/StringManipulationGroup -.-> java/strings("`Strings`") java/BasicSyntaxGroup -.-> java/type_casting("`Type Casting`") java/BasicSyntaxGroup -.-> java/variables("`Variables`") java/SystemandDataProcessingGroup -.-> java/string_methods("`String Methods`") java/SystemandDataProcessingGroup -.-> java/system_methods("`System Methods`") subgraph Lab Skills java/scope -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/classes_objects -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/class_methods -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/modifiers -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/oop -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/user_input -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/wrapper_classes -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/identifier -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/arrays -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/data_types -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/for_loop -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/operators -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/output -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/strings -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/type_casting -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/variables -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/string_methods -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} java/system_methods -.-> lab-117582{{"`Convert Unicode Code Point to Lowercase`"}} end

Setting up the project

  1. Open the terminal of Ubuntu system and navigate to the ~/project directory using the cd command.

  2. Create a new file named CharacterDemo.java. You can use the nano command to create and edit the file.

    touch CharacterDemo.java
  3. In the CharacterDemo.java file, create a public class named CharacterDemo.

    public class CharacterDemo {
    
    }

Using the toLowerCase() method to convert individual characters

  1. Inside the CharacterDemo class, create a public static void main method.

    public static void main(String[] args){
    
    }
  2. Declare and initialize an integer variable named cp to any valid Unicode code point value.

    int cp = 67;
  3. Invoke the toLowerCase() method and pass the cp variable as a parameter.

    char lowerCaseChar = Character.toLowerCase((char)cp);
  4. Print the lowercase character to the console.

    System.out.println("Lowercase character: " + lowerCaseChar);
  5. Save the file and exit the editor.

Using the toLowerCase() method in a loop

  1. Inside the main method, create a string variable named inputString and initialize it with any string of your choice.

    String inputString = "HELLO";
  2. Create a character array named charArray and initialize it by converting inputString to a character array using the toCharArray() method.

    char[] charArray = inputString.toCharArray();
  3. Use a for loop to iterate through each character in the charArray.

    for(int i=0; i<charArray.length; i++){
    
    }
  4. Inside the for loop, invoke the toLowerCase() method and pass the current character of the charArray as a parameter.

    char lowercaseChar = Character.toLowerCase(charArray[i]);
  5. Print the lowercase character to the console.

    System.out.print(lowercaseChar);
  6. Save the file and exit the editor.

Using user input to get Unicode code point value

  1. Inside the main method, create an instance of the Scanner class to get user input.

    Scanner scanner = new Scanner(System.in);
  2. Output a message to the user to enter a Unicode code point value.

    System.out.println("Enter Unicode code point value:");
  3. Use the nextInt() method of the Scanner class to get the user input as an integer.

    int codePoint = scanner.nextInt();
  4. Use the toLowerCase() method and pass the codePoint as a parameter to convert the code point value to its lowercase equivalent.

    char lowercaseChar = Character.toLowerCase((char) codePoint);
  5. Print the lowercase character to the console.

    System.out.println("Lowercase character: " + lowercaseChar);
  6. Save the file and exit the editor.

Compiling and Running the program

  1. Compile the CharacterDemo.java file using the javac command.

    javac CharacterDemo.java
  2. Run the program using the java command.

    java CharacterDemo
  3. Enter the Unicode code point values and observe the output of the program.

  4. Congratulations! You have successfully completed the lab.

Summary

In this lab, we learned how to use the toLowerCase(int codePoint) method in Java to convert Unicode code point values to their lowercase equivalents. We also learned how to use the Scanner class to get user input and how to iterate over an array of characters using a for loop.

Other Java Tutorials you may like