GeezerVison is showing docs.oracle.com — Integer (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact1, compact2, compact3
java.lang
Class Integer
-
-
Field Summary
Fields
| Modifier and Type |
Field |
Description |
static int |
BYTES |
The number of bytes used to represent a int value in two's
complement binary form.
|
static int |
MAX_VALUE |
A constant holding the maximum value an int can
have, 231-1.
|
static int |
MIN_VALUE |
A constant holding the minimum value an int can
have, -231.
|
static int |
SIZE |
The number of bits used to represent an int value in two's
complement binary form.
|
static Class<Integer> |
TYPE |
The Class instance representing the primitive type
int.
|
-
Constructor Summary
Constructors
| Constructor |
Description |
Integer(int value) |
Constructs a newly allocated Integer object that
represents the specified int value.
|
Integer(String s) |
Constructs a newly allocated Integer object that
represents the int value indicated by the
String parameter.
|
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
static int |
bitCount(int i) |
Returns the number of one-bits in the two's complement binary
representation of the specified int value.
|
byte |
byteValue() |
Returns the value of this Integer as a byte
after a narrowing primitive conversion.
|
static int |
compare(int x,
int y) |
Compares two int values numerically.
|
int |
compareTo(Integer anotherInteger) |
Compares two Integer objects numerically.
|
static int |
compareUnsigned(int x,
int y) |
Compares two int values numerically treating the values
as unsigned.
|
static Integer |
decode(String nm) |
Decodes a String into an Integer.
|
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.
|
double |
doubleValue() |
Returns the value of this Integer as a double
after a widening primitive conversion.
|
boolean |
equals(Object obj) |
Compares this object to the specified object.
|
float |
floatValue() |
Returns the value of this Integer as a float
after a widening primitive conversion.
|
static Integer |
getInteger(String nm) |
Determines the integer value of the system property with the
specified name.
|
static Integer |
getInteger(String nm,
int val) |
Determines the integer value of the system property with the
specified name.
|
static Integer |
getInteger(String nm,
Integer val) |
Returns the integer value of the system property with the
specified name.
|
int |
hashCode() |
Returns a hash code for this Integer.
|
static int |
hashCode(int value) |
Returns a hash code for a int value; compatible with
Integer.hashCode().
|
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.
|
int |
intValue() |
Returns the value of this Integer as an
int.
|
long |
longValue() |
Returns the value of this Integer as a long
after a widening primitive conversion.
|
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.
|
static int |
max(int a,
int b) |
Returns the greater of two int values
as if by calling Math.max.
|
static int |
min(int a,
int b) |
Returns the smaller of two int values
as if by calling Math.min.
|
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.
|
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.
|
static int |
parseInt(String s) |
Parses the string argument as a signed decimal integer.
|
static int |
parseInt(String s,
int radix) |
Parses the string argument as a signed integer in the radix
specified by the second argument.
|
static int |
parseUnsignedInt(String s) |
Parses the string argument as an unsigned decimal integer.
|
static int |
parseUnsignedInt(String s,
int radix) |
Parses the string argument as an unsigned integer in the radix
specified by the second argument.
|
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.
|
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.
|
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.
|
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.
|
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.
|
short |
shortValue() |
Returns the value of this Integer as a short
after a narrowing primitive conversion.
|
static int |
signum(int i) |
Returns the signum function of the specified int value.
|
static int |
sum(int a,
int b) |
Adds two integers together as per the + operator.
|
static String |
toBinaryString(int i) |
Returns a string representation of the integer argument as an
unsigned integer in base 2.
|
static String |
toHexString(int i) |
Returns a string representation of the integer argument as an
unsigned integer in base 16.
|
static String |
toOctalString(int i) |
Returns a string representation of the integer argument as an
unsigned integer in base 8.
|
String |
toString() |
Returns a String object representing this
Integer's value.
|
static String |
toString(int i) |
Returns a String object representing the
specified integer.
|
static String |
toString(int i,
int radix) |
Returns a string representation of the first argument in the
radix specified by the second argument.
|
static long |
toUnsignedLong(int x) |
Converts the argument to a long by an unsigned
conversion.
|
static String |
toUnsignedString(int i) |
Returns a string representation of the argument as an unsigned
decimal value.
|
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.
|
static Integer |
valueOf(int i) |
Returns an Integer instance representing the specified
int value.
|
static Integer |
valueOf(String s) |
Returns an Integer object holding the
value of the specified String.
|
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.
|
-
-
Field Detail
-
MIN_VALUE
@Native
public static final int MIN_VALUE
A constant holding the minimum value an int can
have, -231.
- See Also:
- Constant Field Values
-
MAX_VALUE
@Native
public static final int MAX_VALUE
A constant holding the maximum value an int can
have, 231-1.
- See Also:
- Constant Field Values
-
Constructor Detail
-
Integer
public Integer(String s)
throws NumberFormatException
Constructs a newly allocated Integer object that
represents the int value indicated by the
String parameter. The string is converted to an
int value in exactly the manner used by the
parseInt method for radix 10.
- Parameters:
s - the String to be converted to an
Integer.
- Throws:
NumberFormatException - if the String does not
contain a parsable integer.
- See Also:
parseInt(java.lang.String, int)
-
Method Detail
-
toString
public String toString()
Returns a String object representing this
Integer's value. The value is converted to signed
decimal representation and returned as a string, exactly as if
the integer value were given as an argument to the toString(int) method.
- Overrides:
toString in class Object
- Returns:
- a string representation of the value of this object in
base 10.
-
equals
public boolean equals(Object obj)
Compares this object to the specified object. The result is
true if and only if the argument is not
null and is an Integer object that
contains the same int value as this object.
- Overrides:
equals in class Object
- Parameters:
obj - the object to compare with.
- Returns:
true if the objects are the same;
false otherwise.
- See Also:
Object.hashCode(),
HashMap
-
compareUnsigned
public static int compareUnsigned(int x,
int y)
Compares two int values numerically treating the values
as unsigned.
- Parameters:
x - the first int to compare
y - the second int to compare
- Returns:
- the value
0 if x == y; a value less
than 0 if x < y as unsigned values; and
a value greater than 0 if x > y as
unsigned values
- Since:
- 1.8
-
toUnsignedLong
public static long toUnsignedLong(int x)
Converts the argument to a long by an unsigned
conversion. In an unsigned conversion to a long, the
high-order 32 bits of the long are zero and the
low-order 32 bits are equal to the bits of the integer
argument.
Consequently, zero and positive int values are mapped
to a numerically equal long value and negative int values are mapped to a long value equal to the
input plus 232.
- Parameters:
x - the value to convert to an unsigned long
- Returns:
- the argument converted to
long by an unsigned
conversion
- Since:
- 1.8
-
remainderUnsigned
public 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.
- Parameters:
dividend - the value to be divided
divisor - the value doing the dividing
- Returns:
- the unsigned remainder of the first argument divided by
the second argument
- Since:
- 1.8
- See Also:
divideUnsigned(int, int)
-
highestOneBit
public 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. Returns zero if the specified value has no
one-bits in its two's complement binary representation, that is, if it
is equal to zero.
- Parameters:
i - the value whose highest one bit is to be computed
- Returns:
- an
int value with a single one-bit, in the position
of the highest-order one-bit in the specified value, or zero if
the specified value is itself equal to zero.
- Since:
- 1.5
-
lowestOneBit
public 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. Returns zero if the specified value has no
one-bits in its two's complement binary representation, that is, if it
is equal to zero.
- Parameters:
i - the value whose lowest one bit is to be computed
- Returns:
- an
int value with a single one-bit, in the position
of the lowest-order one-bit in the specified value, or zero if
the specified value is itself equal to zero.
- Since:
- 1.5
-
numberOfTrailingZeros
public 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. Returns 32 if the specified value has no
one-bits in its two's complement representation, in other words if it is
equal to zero.
- Parameters:
i - the value whose number of trailing zeros is to be computed
- 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, or 32 if the value is equal
to zero.
- Since:
- 1.5
-
bitCount
public static int bitCount(int i)
Returns the number of one-bits in the two's complement binary
representation of the specified int value. This function is
sometimes referred to as the population count.
- Parameters:
i - the value whose bits are to be counted
- Returns:
- the number of one-bits in the two's complement binary
representation of the specified
int value.
- Since:
- 1.5
-
signum
public static int signum(int i)
Returns the signum function of the specified int value. (The
return value is -1 if the specified value is negative; 0 if the
specified value is zero; and 1 if the specified value is positive.)
- Parameters:
i - the value whose signum is to be computed
- Returns:
- the signum function of the specified
int value.
- Since:
- 1.5
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|