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/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/exceptions("`Exceptions`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/modifiers("`Modifiers`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/oop("`OOP`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/packages_api("`Packages / API`") 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/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/system_methods("`System Methods`") subgraph Lab Skills java/scope -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/classes_objects -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/class_methods -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/exceptions -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/modifiers -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/oop -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/packages_api -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/user_input -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/wrapper_classes -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/identifier -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/arrays -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/data_types -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/operators -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/output -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/strings -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/type_casting -.-> lab-117557{{"`Determining Titlecase Characters in Java`"}} java/variables -.-> 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.

Other Java Tutorials you may like