isNumericSpace()
is a StringUtils
class that checks if the given string contains only Unicode digits or space.
If the given string is a decimal
point, then the method returns false
as the decimal point is not considered to be a Unicode
digit.
The method returns false
if the input string is null
.
The method returns true
if the input string is empty.
StringUtils
StringUtils
is defined in the Apache Commons Lang
package. To add the Apache Commons Lang
package to the Maven project, add the following dependency to the pom.xml
file.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
For other versions of the commons-lang package, refer to the Maven Repository.
You can import the StringUtils
class as follows.
import org.apache.commons.lang3.StringUtils;
public static boolean isNumericSpace(final CharSequence cs)
final CharSequence cs
: the character sequence/string to check.
This method returns true
if the string is not null
and contains only Unicode
digits or space. Otherwise, it returns false
.
string - "543234"
The method returns true
as the string contains only Unicode digits.
string - "54 3 234 "
The method returns true
as the string contains only Unicode digits and space.
string - "१ २"
The method returns true
as the string contains only Unicode digits and space.
string - "ingf-2edf"
The method returns false
as the string contains Unicode letters.
import org.apache.commons.lang3.StringUtils;public class Main {public static void main(String[] args) {String s = "543234";System.out.printf("The output of StringUtils.isNumericSpace() for the string - '%s' is %s",s, StringUtils.isNumericSpace(s));System.out.println();s = "54 3 234 ";System.out.printf("The output of StringUtils.isNumericSpace() for the string - '%s' is %s",s, StringUtils.isNumericSpace(s));System.out.println();s = "\u0967 \u0968";System.out.printf("The output of StringUtils.isNumericSpace() for the string - '%s' is %s",s, StringUtils.isNumericSpace(s));System.out.println();s = "ingf-2edf";System.out.printf("The output of StringUtils.isNumericSpace() for the string - '%s' is %s",s, StringUtils.isNumericSpace(s));System.out.println();}}
The output of the code will be as follows.
The output of StringUtils.isNumericSpace() for the string - '543234' is true
The output of StringUtils.isNumericSpace() for the string - '54 3 234 ' is true
The output of StringUtils.isNumericSpace() for the string - '१ २' is true
The output of StringUtils.isNumericSpace() for the string - 'ingf-2edf' is false