➤ How to Code a Game
➤ Array Programs in Java
➤ Java Inline Thread Creation
➤ Java Custom Exception
➤ Hibernate vs JDBC
➤ Object Relational Mapping
➤ Check Oracle DB Size
➤ Check Oracle DB Version
➤ Generation of Computers
➤ XML Pros & Cons
➤ Git Analytics & Its Uses
➤ Top Skills for Cloud Professional
➤ How to Hire Best Candidates
➤ Scrum Master Roles & Work
➤ CyberSecurity in Python
➤ Protect from Cyber-Attack
➤ Solve App Development Challenges
➤ Top Chrome Extensions for Twitch Users
➤ Mistakes That Can Ruin Your Test Metric Program
StringUtils isNumeric() Java | The isNumeric() method is the static method in the StringUtils method that checks whether the string contains Unicode digits or not. This method returns false if the string has decimal values as decimal values are not considered Unicode digits and also it returns false if it contains null or the string is empty. Also see:- Unicode character set in Java
Java StringUtils isNumeric() Method
The syntax for the isNumeric method is as follows:- public static boolean isNumeric(final CharSequence cs)
Parameters: cs – the string which needed to be checked whether it contains Unicode digits or not.
Return type: boolean
Returns: true if the string contains Unicode or else returns false.
StringUtils isNumeric() method checks if the CharSequence contains only Unicode digits. A decimal point is not a Unicode digit and returns false. The null will return false. An empty CharSequence (length()=0) will return false.
Note that the method does not allow for a leading sign, either positive or negative. Also, if a String passes the numeric test, it may still generate a NumberFormatException when parsed by Integer.parseInt or Long.parseLong, e.g. if the value is outside the range for int or long respectively.
Java isNumeric() StringUtils Example
Let us see some examples of StringUtils.isNumeric() method.
import org.apache.commons.lang3.StringUtils;
public class Main {
public static void main(String[] args) {
String string = "4789652";
System.out.println(StringUtils.isNumeric(string));
}
}
Output:-
true
import org.apache.commons.lang3.StringUtils;
public class Main {
public static void main(String[] args) {
String string = "Hi ";
System.out.println(StringUtils.isNumeric(string));
}
}
Output:-
false
import org.apache.commons.lang3.StringUtils;
public class Main {
public static void main(String[] args) {
String string = "\u0967\u0968";
System.out.println(StringUtils.isNumeric(string));
System.out.println("String: " + string);
}
}
Output:-
true
String: १२
import org.apache.commons.lang3.StringUtils;
public class Main {
public static void main(String[] args) {
String string = " ";
System.out.println(StringUtils.isNumeric(string));
}
}
Output:-
false
import org.apache.commons.lang3.StringUtils;
public class Main {
public static void main(String[] args) {
String string = "-1334";
System.out.println(StringUtils.isNumeric(string));
}
}
Output:-
false
Since StringUtils.isNumeric() method doesn’t allow a leading sign therefore StringUtils.isNumeric() method return false for the number = -1334.
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!