Java.lang.Integer Class

Java Integer Class

The Integer class in the Java.lang, i.e Java.lang.Integer package encapsulates a value of the primitive type int in an object. A single field of type int exists in an object of type Integer.

This class also has various methods for converting an int to a String and a String to an int, as well as additional constants and methods that are handy when working with int. Let us see the class declaration in Java.lang.Integer.

Class declaration

The declaration of java.lang.Integer class is:

 

public final class Integer
  extends Number
    implements Comparable<Integer>

Fields

S.N Fields & Description
1. static int BYTES
The number of bytes used to represent a int value in two’s complement binary form.
2. static int MAX_VALUE
A constant holding the maximum value an int can have, 231-1.
3. static int MIN_VALUE
A constant holding the minimum value an int can have, -231.
4. static int SIZE
The number of bits used to represent an int value in two’s complement binary form.
5. static Class<Integer> TYPE
The Class instance representing the primitive type int.

java.lang.Integer Methods

 

The java.lang.Integer class has a number of methods which are listed below:

 

Member Methods

 

S.N Methods & Description
1. static int bitCount(int i)
Returns the number of one-bits in the two’s complement binary representation of the specified int value.
2. byte byteValue()
Returns the value of this Integer as a byte after a narrowing primitive conversion.
3. static int compare(int x, int y)
Compares two int values numerically.
4. int compareTo(Integer anotherInteger)
Compares two Integer objects numerically.
5. static int compareUnsigned(int x, int y)
Compares two int values numerically treating the values as unsigned.
6. static Integer decode(String nm)
Decodes a String into an Integer.
7. static int divideUnsigned(int dividend, int divisor)
Returns the unsigned quotient of dividing the first argument by the second where each argument and the result is interpreted as an unsigned value.
8. double doubleValue()
Returns the value of this Integer as a double after a widening primitive conversion.
9. boolean equals(Object obj)
Compares this object to the specified object.
10. float floatValue()
Returns the value of this Integer as a float after a widening primitive conversion.
11. static Integer getInteger(String nm)
Determines the integer value of the system property with the specified name.
12. static Integer getInteger(String nm, int val)
Determines the integer value of the system property with the specified name.
13. static Integer getInteger(String nm, Integer val)
Returns the integer value of the system property with the specified name.
14. int hashCode()
Returns a hash code for this Integer.
15. static int hashCode(int value)
Returns a hash code for a int value; compatible with Integer.hashCode().
16. static int highestOneBit(int i)
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.
17. int intValue()
Returns the value of this Integer as an int.
18. long longValue()
Returns the value of this Integer as a long after a widening primitive conversion.
19. static int lowestOneBit(int i)
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.
20. static int max(int a, int b)
Returns the greater of two int values as if by calling Math.max.
21. static int min(int a, int b)
Returns the smaller of two int values as if by calling Math.min.
22. static int numberOfLeadingZeros(int i)
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.
23. static int numberOfTrailingZeros(int i)
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.
24. static int parseInt(String s)
Parses the string argument as a signed decimal integer.
25. static int parseInt(String s, int radix)
Parses the string argument as a signed integer in the radix specified by the second argument.
26. static int parseUnsignedInt(String s)
Parses the string argument as an unsigned decimal integer.
27. static int parseUnsignedInt(String s, int radix)
Parses the string argument as an unsigned integer in the radix specified by the second argument.
28. static int remainderUnsigned(int dividend, int divisor)
Returns the unsigned remainder from dividing the first argument by the second where each argument and the result is interpreted as an unsigned value.
29. static int reverse(int i)
Returns the value obtained by reversing the order of the bits in the two’s complement binary representation of the specified int value.
30. static int reverseBytes(int i)
Returns the value obtained by reversing the order of the bytes in the two’s complement representation of the specified int value.
31. static int rotateLeft(int i, int distance)
Returns the value obtained by rotating the two’s complement binary representation of the specified int value left by the specified number of bits.
32. static int rotateRight(int i, int distance)
Returns the value obtained by rotating the two’s complement binary representation of the specified int value right by the specified number of bits.
33. short shortValue()
Returns the value of this Integer as a short after a narrowing primitive conversion.
34. static int signum(int i)
Returns the signum function of the specified int value.
35. static int sum(int a, int b)
Adds two integers together as per the + operator.
36. static String toBinaryString(int i)
Returns a string representation of the integer argument as an unsigned integer in base 2.
37. static String toHexString(int i)
Returns a string representation of the integer argument as an unsigned integer in base 16.
38. static String toOctalString(int i)
Returns a string representation of the integer argument as an unsigned integer in base 8.
39. String toString()
Returns a String object representing this Integer’s value.
40. static String toString(int i)
Returns a String object representing the specified integer.
41. static String toString(int i, int radix)
Returns a string representation of the first argument in the radix specified by the second argument.
42. static long toUnsignedLong(int x)
Converts the argument to a long by an unsigned conversion.
43. static String toUnsignedString(int i)
Returns a string representation of the argument as an unsigned decimal value.
44. static String toUnsignedString(int i, int radix)
Returns a string representation of the first argument as an unsigned integer value in the radix specified by the second argument.
45. static Integer valueOf(int i)
Returns an Integer instance representing the specified int value.
46. static Integer valueOf(String s)
Returns an Integer object holding the value of the specified String.
47. static Integer valueOf(String s, int radix)
Returns an Integer object holding the value extracted from the specified String when parsed with the radix given by the second argument.

Methods inherited

The Java.lang.Integer class inherits the methods of the following class:

  • java.lang.Object
  • java.lang.Number

 

To open the online compiler click here.

 

Also Read: Java – While Loop

Leave a Reply

Your email address will not be published. Required fields are marked *