Introducing Integer

The Integer class is part of the java.lang package.

The Integer class is a wrapper class for the primitive type int. It contains several methods to effectively deal with an integer. An object of an Integer class can hold a single int value.

Note: To get an overview of what a wrapper class is, check out this shot.

Creating an Integer object

This class has two constructors:

  • Integer (int value)
  • Integer (String string)

Let’s cover them one by one.

The Integer (int value) constructor

This constructor constructs a new Integer object that represents the specified int value.

Look at the program below.

Get hands-on with 1200+ tech skills courses.