Java String check - easy question probably

not sure if there is a command, maybe there is and i havent found it but.

i have an input: MapLinIn.
i want to make sure that its length is equal to 3. i have done that with line below:

if (MapLinkIn.length()==3)

i now want to make sure that all 3 of the chars in the string are integers
so only say 123 was accepted or 012 etc etc

is it posible to make sure all the chars in the input are integers and if so how :)

many many thanks

Gareth
PowerMaxUKAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
If

Integer.parseInt(MapLinkln)

doesn't throw a NumberFormatException, then you're fine
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
allahabadCommented:
try {
String mapLink = Integer.parseInt(MapLinkIn);
}catch(NumberFormatExcetion e){
// not a number
  System.out.println("This is not a number");
}
0
CEHJCommented:
Please do not repeat other people's answers allahabad. How many times do i have to say this to you?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

PowerMaxUKAuthor Commented:
thank u :)

knew it was probably easy!

thanks
Gareth
0
PowerMaxUKAuthor Commented:
its saying:

incompatible types
found   : int
required: java.lang.String
String MapLinkTest = Integer.parseInt(MapLinkIn);

Thanks G
0
girionisCommented:
 Change this:

  String MapLinkTest = Integer.parseInt(MapLinkIn);

  to this:

  int MapLinkTest = Integer.parseInt(MapLinkIn);

  Also, as a good programming practice, I recommend you have all variable names start with lowercase letters. :-)
0
PowerMaxUKAuthor Commented:
ok, i now have:

try
{
int MapLinkTest = Integer.parseInt(MapLinkIn);
System.out.println(MapLinkTest);

}
catch(NumberFormatException e)
{
ProjectDBase.EditOutputTextField.setText("Map Link Error - Not in range, try again");
}

it doesnt throw the exception when i put XXX into the input, ideas?

G
0
CEHJCommented:
Are you sure? Try:

catch(NumberFormatException e)
{
e.printStackTrace();
ProjectDBase.EditOutputTextField.setText("Map Link Error - Not in range, try again");
}
0
PowerMaxUKAuthor Commented:
ooh yes sorry CEHJ but thanks for that idea made me realise i was overwriting later on!

thanks again for the quick answer!

Gareth
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.