A project I am working on requires me to check the first character of an input string, to determine if it is a numeric character. I have developed the following code:
public static boolean IsLeadingCharNumfName(String fName)
{
CharSequence[] numbs;
numbs = new CharSequence[10];
numbs[0] = "0";
numbs[1] = "1";
numbs[2] = "2";
numbs[3] = "3";
numbs[4] = "4";
numbs[5] = "5";
numbs[6] = "6";
numbs[7] = "7";
numbs[8] = "8";
numbs[9] = "9";
if(fName.substring(0,1).equals(numbs[0]))
{
return true;
}
if(fName.substring(0,1).equals(numbs[1]))
{
return true;
}
if(fName.substring(0,1).equals(numbs[2]))
{
return true;
}
if(fName.substring(0,1).equals(numbs[3]))
{
return true;
}
if(fName.substring(0,1).equals(numbs[4]))
{
return true;
}
if(fName.substring(0,1).equals(numbs[5]))
{
return true;
}
if(fName.substring(0,1).equals(numbs[6]))
{
return true;
}
if(fName.substring(0,1).equals(numbs[7]))
{
return true;
}
if(fName.substring(0,1).equals(numbs[8]))
{
return true;
}
if(fName.substring(0,1).equals(numbs[9]))
{
return true;
}
else
{
return false;
}
}
I feel that this code can be optimised for efficiency, but I'm not sure how. I'll have to do the same for checking if the name contains a number.
What I am looking for, is a way to lower the code footprint primarily, with efficiency as a secondary bonus.