Java Integer Methods

Beginner
6 min read
Updated: Nov 2026
37 method guides
Method index

About This Index

This page is the Java Integer Methods index. Each row links to a full guide with syntax, parameters, return value, three runnable examples, and FAQs. Every example is a complete Java class with a main method and fixed data, and all of them compile on Java 8 and later.

New to Integer? It is the wrapper class for the primitive int, and it lives in java.lang, so you never import it. An int is a 32-bit whole number from Integer.MIN_VALUE (−2147483648) to Integer.MAX_VALUE (2147483647). Java boxes an int into an Integer automatically when a collection needs an object, and the class also holds helpers such as parseInt(), toString(), and compare().

Static or instance?

Most of these methods are static: you call them on the class, as in Integer.parseInt("42"). A few are instance methods that work on an Integer object, as in count.intValue(). Each guide tells you which one it is. Also remember that an int wraps around silently when it overflows, so Integer.MAX_VALUE + 1 becomes Integer.MIN_VALUE.

How to Call an Integer Method

Call a static method on the class, and an instance method on a variable:

Java
int age = Integer.parseInt("42");          // static: text to int
String bits = Integer.toBinaryString(age);  // static: int to text, "101010"
int bigger = Integer.max(age, 100);         // static: 100

Integer boxed = Integer.valueOf(age);       // static: int to Integer
long wide = boxed.longValue();              // instance: 42
int order = boxed.compareTo(50);            // instance: -1

Java Integer Methods Table

All method guides in this Java tutorial series (37 tutorials), grouped by purpose.

Text to number

5 methods

Turn a String into an int or an Integer: plain decimal numbers, other bases, hex and octal prefixes, unsigned values, and numbers stored in system properties.

MethodDescriptionTutorial
parseInt()Convert a String of digits into an int.Try it
parseUnsignedInt()Read text as an unsigned 32-bit number.Try it
valueOf()Get an Integer object from an int or a String.Try it
decode()Parse text that may use a 0x, #, or 0 prefix.Try it
getInteger()Read an int from a system property.Try it

Number to text

5 methods

Turn an int into a String in decimal, in any base from 2 to 36, or as raw binary, hex, and octal bits.

MethodDescriptionTutorial
toString()Convert an int to text, in base 10 or any base.Try it
toBinaryString()Show the bits of an int as a binary String.Try it
toHexString()Show the bits of an int in hexadecimal.Try it
toOctalString()Show the bits of an int in octal (base 8).Try it
toUnsignedString()Print an int as an unsigned decimal number.Try it

Compare and pick

8 methods

Compare two numbers, test equality, get a hash code, find the larger or smaller value, and read the sign of a number.

MethodDescriptionTutorial
compare()Compare two int values safely: negative, zero, or positive.Try it
compareTo()Compare an Integer object with another Integer.Try it
compareUnsigned()Compare two ints as unsigned 32-bit numbers.Try it
equals()Check whether an Integer equals another object.Try it
hashCode()Get the hash code of an Integer (its own value).Try it
max()Return the larger of two int values.Try it
min()Return the smaller of two int values.Try it
signum()Get -1, 0, or 1 for a negative, zero, or positive number.Try it

Arithmetic and unsigned math

4 methods

Add two ints as a method call, and treat the 32 bits of an int as an unsigned number for division, remainders, and widening to long.

MethodDescriptionTutorial
sum()Add two int values, as a method you can pass around.Try it
divideUnsigned()Divide two ints as unsigned 32-bit numbers.Try it
remainderUnsigned()Get the remainder of an unsigned division.Try it
toUnsignedLong()Widen an int to a long as an unsigned value.Try it

Bit tricks

9 methods

Count bits, find the highest or lowest set bit, count leading and trailing zeros, reverse bits or bytes, and rotate bits left or right.

MethodDescriptionTutorial
bitCount()Count the 1 bits in the binary form of an int.Try it
highestOneBit()Keep only the leftmost 1 bit of an int.Try it
lowestOneBit()Keep only the rightmost 1 bit of an int.Try it
numberOfLeadingZeros()Count the zero bits before the first 1 bit.Try it
numberOfTrailingZeros()Count the zero bits after the last 1 bit.Try it
reverse()Reverse the order of all 32 bits of an int.Try it
reverseBytes()Reverse the order of the four bytes of an int.Try it
rotateLeft()Rotate the bits of an int to the left in a circle.Try it
rotateRight()Rotate the bits of an int to the right in a circle.Try it

Convert to other number types

6 methods

Unwrap an Integer to a primitive: int, long, double, float, short, or byte, and see what happens when the value does not fit.

MethodDescriptionTutorial
intValue()Unwrap an Integer into a primitive int.Try it
longValue()Widen an Integer to a primitive long.Try it
doubleValue()Convert an Integer to a primitive double.Try it
floatValue()Convert an Integer to a primitive float.Try it
shortValue()Narrow an Integer to a primitive short.Try it
byteValue()Narrow an Integer to a primitive byte.Try it

Frequently Asked Questions

They are the methods of java.lang.Integer, the wrapper class for the primitive int. They convert text to numbers and numbers to text, compare and combine values, work with the individual bits of an int, and convert an Integer to other number types.
This index lists 37 guides, from parseInt() and toString() to bitCount(), rotateLeft(), and divideUnsigned(), grouped by what they do.
Most are static, so you call them on the class, such as Integer.parseInt("42"). The instance methods are intValue(), longValue(), doubleValue(), floatValue(), shortValue(), byteValue(), compareTo(), equals(), hashCode(), and toString(), which you call on an Integer object.
compareUnsigned(), divideUnsigned(), remainderUnsigned(), parseUnsignedInt(), toUnsignedLong(), toUnsignedString(), max(), min(), sum(), and the static hashCode(int). Every other method here works on older versions of Java.
Open parseInt(), toString(), and compare() first. Then try toBinaryString() and bitCount() to see how an int looks in bits.

Start with bitCount()

Count the 1 bits in an int, the first guide in the list.

bitCount() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful