- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a string contains a number using Java.
To find whether a given string contains a number, convert it to a character array and find whether each character in the array is a digit using the isDigit() method of the Character class.
Example
public class ContainsExample { public static void main(String args[]){ String sample = "krishna64"; char[] chars = sample.toCharArray(); StringBuilder sb = new StringBuilder(); for(char c : chars){ if(Character.isDigit(c)){ sb.append(c); } } System.out.println(sb); } }
Output
64
- Related Articles
- Check if a string contains only alphabets in Java using Regex
- Check if a string contains only alphabets in Java using Lambda expression
- Check if a string contains only alphabets in Java using ASCII values
- Java Program to Check if a string contains a substring
- Java Regular expression to check if a string contains alphabet
- Method to check if a String contains a sub string ignoring case in Java
- PHP 8 – Using str_contains() to check if a string contains a substring
- Java program to check if a string contains any special character
- Check if a string contains a sub-string in C++
- How to check if array contains a duplicate number using C#?
- Check if a field contains a string in MongoDB?
- Check if a String Contains a Substring in Linux
- How to check if a string contains a specific sub string?
- Check if a string contains numbers in MySQL?
- How to check if a String contains another String in a case insensitive manner in Java?

Advertisements