Indicated String stras your input line:
Option number 1:
public static boolean isHex(String str)
{
try
{
int val = Integer.parseInt(str,16);
}
catch (Exception e)
{
return false;
}
return true;
}
Option number 2:
private static boolean[] hash = new boolean[Character.MAX_VALUE];
static
{
for (int i=0; i<hash.length; i++)
hash[i] = false;
for (char c : "0123456789ABCDEFabcdef".toCharArray())
hash[c] = true;
}
public static boolean isHex(String str)
{
for (char c : str.toCharArray())
if (!hash[c])
return false;
return true;
}
source
share