How to Check If a String is an Integer in Java


Choose an answer and hit 'next'. You will receive your score and answers at the end.

question 1 of 3

Examine the following Java code. What would happen if the string did NOT include an integer?

Create Your Account To Take This Quiz

As a member, you'll also get unlimited access to over 79,000 lessons in math, English, science, history, and more. Plus, get practice tests, quizzes, and personalized coaching to help you succeed.

Try it risk-free
Try it risk-free for 30 days. Cancel anytime
Already registered? Log in here for access

1. Which of the following would be the best way to test for an Integer in a string in Java?

2. Based on the Java code below, which of the item(s) in the array coolString would pass the Integer test, therefore parseInt would be successful?

Create your account to access this entire worksheet
A Premium account gives you access to all lesson, practice exams, quizzes & worksheets
Access to all video lessons
Quizzes, practice exams & worksheets
Certificate of Completion
Access to instructors
Create an account to get started Create Account

About This Quiz and Worksheet

Inside this quiz and worksheet, you can review ways to check if a string is an integer in the Java language. Questions ask you about the best way to test for integers, along with additions to make in case of compiling errors.

Quiz and Worksheet Goals

You can find the topics mentioned below in the questions for this quiz:

  • What happens if a string does not include an integer
  • Proper ways to test for integers
  • Successfully passing integer tests
  • Adding code in case of errors

Skills Practiced

  • Information recall - remember what you have learned about integers in Java, including the parseInt function
  • Knowledge application - use what you know to answer questions about the best way to check for an integer
  • Making connections - understand what happens when a string does not include an integer in a given set of code

Additional Learning

For some more practice, head over to the lesson titled How to Check If a String is an Integer in Java. Inside, you can find the extra material mentioned below:

  • Potential error messages
  • Try/catch
  • More examples of code