Provides extra functionality for Java Number classes.
* * @author Rand McNeely * @author Stephen Colebourne * @author Steve Downey * @author Eric Pugh * @author Phil Steitz * @author Matthew Hawthorne * @author Gary Gregory * @author Fredrik Westermarck * @since 2.0 * @version $Id: NumberUtils.java 609475 2008-01-06 23:58:59Z bayard $ */ public class Main { /** *Checks whether the String
contains only
* digit characters.
Null
and empty String will return
* false
.
String
to check
* @return true
if str contains only unicode numeric
*/
public static boolean isDigits(String str) {
if (isEmpty(str)) {
return false;
}
for (int i = 0; i < str.length(); i++) {
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
return true;
}
// Empty checks
//-----------------------------------------------------------------------
/**
* Checks if a String is empty ("") or null.
* ** StringUtils.isEmpty(null) = true * StringUtils.isEmpty("") = true * StringUtils.isEmpty(" ") = false * StringUtils.isEmpty("bob") = false * StringUtils.isEmpty(" bob ") = false ** *
NOTE: This method changed in Lang version 2.0. * It no longer trims the String. * That functionality is available in isBlank().
* * @param str the String to check, may be null * @returntrue
if the String is empty or null
*/
public static boolean isEmpty(String str) {
return str == null || str.length() == 0;
}
}