

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check if a given character is a number/letter in Java?
The Character class is a subclass of Object class and it wraps a value of the primitive type char in an object. An object of type Character contains a single field whose type is char. We can check whether the given character in a string is a number/letter by using isDigit() method of Character class. The isDigit() method is a static method and determines if the specified character is a digit.
Example
public class CharacterIsNumberOrDigitTest { public static void main(String[] args) { String str = "Tutorials123"; for(int i=0; i < str.length(); i++) { Boolean flag = Character.isDigit(str.charAt(i)); if(flag) { System.out.println("'"+ str.charAt(i)+"' is a number"); } else { System.out.println("'"+ str.charAt(i)+"' is a letter"); } } } }
Output
'T' is a letter 'u' is a letter 't' is a letter 'o' is a letter 'r' is a letter 'i' is a letter 'a' is a letter 'l' is a letter 's' is a letter '1' is a number '2' is a number '3' is a number
- Related Questions & Answers
- How to check if a character in a string is a letter in Python?
- Check if input is a number or letter in JavaScript?
- Java Program for check if a given number is Fibonacci number?
- How to check if a given number is a Fibonacci number in Python Program ?
- Python Program for How to check if a given number is a Fibonacci number?
- Check if a given number is Pronic in C++
- C# Program to check if a character is a whitespace character
- Check if a given string is a valid number in Python
- Check if a given string is a valid number in C++
- Python program to check if the given number is a Disarium Number
- Check whether the Unicode character is a lowercase letter in C#
- Check if a given mobile number is fancy in C++
- Check if a character is alphanumeric in Arduino
- Check if a character is printable in Arduino
- Python program to check if a given string is number Palindrome
Advertisements