Java.lang.Integer Class

Java.lang.Integer Class

Introduction

The java.lang.Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.

Class declaration

Following is the declaration for java.lang.Integer class:

public final class Integer
  extends Number
    implements Comparable<Integer>

Field

Following are the fields for java.lang.Integer class:

  • static int MAX_VALUE — This is a constant holding the maximum value an int can have, 231-1.
  • static int MIN_VALUE — This is a constant holding the minimum value an int can have, -231.
  • static int SIZE — This is the number of bits used to represent an int value in two’s complement binary form.
  • static Class<Integer> TYPE — This is the class instance representing the primitive type int.

Class constructors

S.N.Constructor & Description
1Integer(int value)

This constructs a newly allocated Integer object that represents the specified int value.

2Integer(String s)

This constructs a newly allocated Integer object that represents the int value indicated by the String parameter.

Class methods

S.N.Method & Description
1static int bitCount(int i)

This method returns the number of one-bits in the two’s complement binary representation of the specified int value.

2byte byteValue()

This method returns the value of this Integer as a byte.

3int compareTo(Integer anotherInteger)

This method compares two Integer objects numerically.

4static Integer decode(String nm)

This method decodes a String into an Integer.

5double doubleValue()

This method returns the value of this Integer as a double.

6boolean equals(Object obj)

This method compares this object to the specified object.

7float floatValue()

This method returns the value of this Integer as a float.

8static Integer getInteger(String nm)

This method determines the integer value of the system property with the specified name.

9static Integer getInteger(String nm, int val)

This method determines the integer value of the system property with the specified name.

10static Integer getInteger(String nm, Integer val)

This method returns the integer value of the system property with the specified name.

11int hashCode()

This method returns a hash code for this Integer.

12static int highestOneBit(int i)

This method returns an int value with at most a single one-bit, in the position of the highest-order (“leftmost”) one-bit in the specified int value.

13int intValue()

This method returns the value of this Integer as an int.

14long longValue()

This method returns the value of this Integer as a long.

15static int lowestOneBit(int i)

This method returns an int value with at most a single one-bit, in the position of the lowest-order (“rightmost”) one-bit in the specified int value.

16static int numberOfLeadingZeros(int i)

This method returns the number of zero bits preceding the highest-order (“leftmost”) one-bit in the two’s complement binary representation of the specified int value.

17static int numberOfTrailingZeros(int i)

This method returns the number of zero bits following the lowest-order (“rightmost”) one-bit in the two’s complement binary representation of the specified int value.

18static int parseInt(String s)

This method parses the string argument as a signed decimal integer.

19static int parseInt(String s, int radix)

This method parses the string argument as a signed integer in the radix specified by the second argument.

20static int reverse(int i)

This method returns the value obtained by reversing the order of the bits in the two’s complement binary representation of the specified int value.

21static int reverseBytes(int i)

This method returns the value obtained by reversing the order of the bytes in the two’s complement representation of the specified int value.

22static int rotateLeft(int i, int distance)

This method returns the value obtained by rotating the two’s complement binary representation of the specified int value left by the specified number of bits.

23static int rotateRight(int i, int distance)

This method returns the value obtained by rotating the two’s complement binary representation of the specified int value right by the specified number of bits.

24short shortValue()

This method returns the value of this Integer as a short.

25static int signum(int i)

This method returns the signum function of the specified int value.

26static String toBinaryString(int i)

This method returns a string representation of the integer argument as an unsigned integer in base 2.

27static String toHexString(int i)

This method returns a string representation of the integer argument as an unsigned integer in base 16.

28static String toOctalString(int i)

This method returns a string representation of the integer argument as an unsigned integer in base 8.

29String toString()

This method returns a String object representing this Integer’s value.

30static String toString(int i)

This method returns a String object representing the specified integer.

31static String toString(int i, int radix)

This method returns a string representation of the first argument in the radix specified by the second argument.

32static Integer valueOf(int i)

This method returns a Integer instance representing the specified int value.

33static Integer valueOf(String s)

This method returns an Integer object holding the value of the specified String.

34static Integer valueOf(String s, int radix)

This method returns an Integer object holding the value extracted from the specified String when parsed with the radix given by the second argument.

Methods inherited

This class inherits methods from the following classes:

  • java.lang.Object

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.