Determining Titlecase Characters in Java

JavaJavaBeginner
Practice Now

Introduction

isTitleCase(int codePoint) is a method in the Java Character class. It checks whether the specified Unicode codepoint character is a Titlecase character or not. This method supports supplementary characters. A character is a title case character if its general category type, provided by Character.getType(ch), is TITLECASE_LETTER.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL java(("Java")) -.-> java/BasicSyntaxGroup(["Basic Syntax"]) java(("Java")) -.-> java/StringManipulationGroup(["String Manipulation"]) java(("Java")) -.-> java/ObjectOrientedandAdvancedConceptsGroup(["Object-Oriented and Advanced Concepts"]) java(("Java")) -.-> java/ConcurrentandNetworkProgrammingGroup(["Concurrent and Network Programming"]) java(("Java")) -.-> java/FileandIOManagementGroup(["File and I/O Management"]) java(("Java")) -.-> java/SystemandDataProcessingGroup(["System and Data Processing"]) java/BasicSyntaxGroup -.-> java/output("Output") java/BasicSyntaxGroup -.-> java/type_casting("Type Casting") java/StringManipulationGroup -.-> java/strings("Strings") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/user_input("User Input") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/exceptions("Exceptions") java/FileandIOManagementGroup -.-> java/files("Files") java/FileandIOManagementGroup -.-> java/create_write_files("Create/Write Files") java/ConcurrentandNetworkProgrammingGroup -.-> java/working("Working") java/SystemandDataProcessingGroup -.-> java/system_methods("System Methods") subgraph Lab Skills java/output -.-> lab-117557{{"Determining Titlecase Characters in Java"}} java/type_casting -.-> lab-117557{{"Determining Titlecase Characters in Java"}} java/strings -.-> lab-117557{{"Determining Titlecase Characters in Java"}} java/user_input -.-> lab-117557{{"Determining Titlecase Characters in Java"}} java/exceptions -.-> lab-117557{{"Determining Titlecase Characters in Java"}} java/files -.-> lab-117557{{"Determining Titlecase Characters in Java"}} java/create_write_files -.-> lab-117557{{"Determining Titlecase Characters in Java"}} java/working -.-> lab-117557{{"Determining Titlecase Characters in Java"}} java/system_methods -.-> lab-117557{{"Determining Titlecase Characters in Java"}} end

Create a Java file

Create a new Java file using the following command:

touch Test.java

Add code to check if a character is a title case character

Add the following code to the Test.java file. This code checks whether five different Unicode codepoint characters are Titlecase characters or not.

public class Test {
  public static void main(String[] args) {
    int cp1 = 0x01c8;
    int cp2 = 60;
    int cp3 = 119;
    int cp4 = 0x01c1;
    int cp5 = 1232;

    boolean b1 = Character.isTitleCase(cp1);
    boolean b2 = Character.isTitleCase(cp2);
    boolean b3 = Character.isTitleCase(cp3);
    boolean b4 = Character.isTitleCase(cp4);
    boolean b5 = Character.isTitleCase(cp5);

    System.out.println((char) cp1 + " is a title case??:  " + b1);
    System.out.println((char) cp2 + " is a title case??:  " + b2);
    System.out.println((char) cp3 + " is a title case??:  " + b3);
    System.out.println((char) cp4 + " is a title case??:  " + b4);
    System.out.println((char) cp5 + " is a title case??:  " + b5);
  }
}

Compile and run the code

Compile the code using the following command:

javac Test.java

Run the code using the following command:

java Test

Provide user input

Add the following code to the Test.java file. This code takes user input and checks whether the provided character is a Titlecase character or not.

import java.util.Scanner;

public class Test {
  public static void main(String[] args) {
    try {
      System.out.print("Enter the Unicode character: ");
      Scanner sc = new Scanner(System.in);
      int cp = sc.nextInt();
      boolean b = Character.isTitleCase(cp);
      System.out.println((char) cp + " is a title case?: " + b);
    } catch (Exception e) {
      System.out.println("Invalid Input!!");
    }
  }
}

Compile and run the code

Compile the code using the following command:

javac Test.java

Run the code using the following command:

java Test

Provide a Unicode character as input and the code will tell you whether it's a Titlecase character or not.

Summary

In this lab, you learned how to use the isTitleCase(int codePoint) method in the Java Character class. You checked whether a specified Unicode codepoint character is a Titlecase character or not. By completing this lab, you should now be able to check whether a particular character is a Titlecase character.