🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
In this guide, you will learn about the Character isDigit() method in Java programming and how to use it with an example.
1. Character isDigit() Method Overview
Definition:
The isDigit() method of the Java Character class determines if a given character (specified as a char or an int code point) is a digit. A character is considered a digit if it's a decimal digit, which means it belongs to the range '0' through '9'.
Syntax:
1. static boolean isDigit(char ch)
2. static boolean isDigit(int codePoint)
Parameters:
char ch: The character to be tested.
int codePoint: The character (Unicode code point) to be tested.
Key Points:
- It is used to ascertain if a character is one of the ten decimal digits.
- The method returns true if the character is a digit, and false otherwise.
- Unicode provides representations for various character sets across languages; therefore, this method can also identify digits in scripts other than Latin (like Arabic numerals).
2. Character isDigit() Method Example
public class IsDigitExample {
public static void main(String[] args) {
char testChar1 = '5';
char testChar2 = 'A';
int testCodePoint = 0x0662; // Arabic numeral '2'
System.out.println("Is '" + testChar1 + "' a digit? " + Character.isDigit(testChar1));
System.out.println("Is '" + testChar2 + "' a digit? " + Character.isDigit(testChar2));
System.out.println("Is Arabic numeral represented by code point " + testCodePoint + " a digit? " + Character.isDigit(testCodePoint));
}
}
Output:
Is '5' a digit? true Is 'A' a digit? false Is Arabic numeral represented by code point 1634 a digit? true
Explanation:
The example demonstrates the isDigit() method by testing two Latin characters and one Arabic numeral. The method identifies the characters '5' and the Arabic numeral represented by the Unicode code point 0x0662 (which is '2' in Arabic) as digits and returns true. However, it returns false for the character 'A' since it's not a digit.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment