You can verify this with a regex.
Assume that (only numerical values):
String a = "493284835"; a.matches("^[0-9]+$");
Assume that (alphanumeric values ββonly):
String a = "dfdf4932fef84835fea"; a.matches("^([A-Za-z]|[0-9])+$");
As Pangea said in the comments area:
If performance is critical, it prefers to compile the regular expression. The following is an example:
String a = "dfdf4932fef84835fea"; Pattern pattern = Pattern.compile("^([A-Za-z]|[0-9])+$"); Matcher matcher = pattern.matcher(a); if (matcher.find()) {
source share