Long
class wraps a value of the primitive type long
in an object. An object of type Long
contains a
single field whose type is long
.
In addition, this class provides several methods for converting
a long
to a String
and a String
to a long
, as well as other constants and methods useful when dealing
with a long
.
This is a value-based class; programmers should treat instances that are equal as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail.
Implementation Note
The implementations of the "bit twiddling"
methods (such as highestOneBit
and
numberOfTrailingZeros
) are
based on material from Henry S. Warren, Jr.'s Hacker's
Delight, (Addison Wesley, 2002).
Modifier and Type | Class and Description |
---|---|
private static class |
Modifier and Type | Field and Description |
---|---|
public static final int | BYTES
The number of bytes used to represent a |
public static final long | MAX_VALUE
A constant holding the maximum value a |
public static final long | MIN_VALUE
A constant holding the minimum value a |
private static final long | serialVersionUID
use serialVersionUID from JDK 1.0.2 for interoperability
|
public static final int | SIZE
The number of bits used to represent a |
public static final Class | TYPE
The |
private final long | value
The value of the |
Access | Constructor and Description |
---|---|
public | Long(long
the value to be represented by the
value)Long object.
Deprecated
for removal since 9. It is rarely appropriate to use this constructor.
Constructs a newly allocated |
public |
Modifier and Type | Method and Description |
---|---|
public static int | Returns: the number of one-bits in the two's complement binary representation of the specifiedlong value.the value whose bits are to be counted i)Returns the number of one-bits in the two's complement binary
representation of the specified |
public byte | byteValue()
Overrides java. Returns the value of this |
public static int | Returns: the value0 if x == y ;
a value less than 0 if x < y ; and
a value greater than 0 if x > y the first x, long long to comparethe second y)long to compareCompares two |
public int | Returns: the value0 if this Long is
equal to the argument Long ; a value less than
0 if this Long is numerically less
than the argument Long ; and a value greater
than 0 if this Long is numerically
greater than the argument Long (signed
comparison).the anotherLong)Long to be compared.Implements java. Compares two |
public static int | Returns: the value0 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 valuesthe first x, long long to comparethe second y)long to compareCompares two |
public static long | Returns: the compressed valuethe value whose bits are to be compressed i, long the bit mask mask)Returns the value obtained by compressing the bits of the
specified |
public static Long | |
public Optional | describeConstable()
Implements java. Returns an |
public static long | Returns: the unsigned quotient of the first argument divided by the second argumentthe value to be divided dividend, long the value doing the dividing 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. |
public double | doubleValue()
Implements abstract java. Returns the value of this |
public boolean | Returns: true if the objects are the same;
false otherwise.the object to compare with. obj)Overrides java. Compares this object to the specified object. |
public static long | Returns: the expanded valuethe value whose bits are to be expanded i, long the bit mask mask)Returns the value obtained by expanding the bits of the
specified |
public float | floatValue()
Implements abstract java. Returns the value of this |
private static void | formatUnsignedLong0(long
the unsigned long to format val, int the log2 of the base to format in (4 for hex, 3 for octal, 1 for binary) shift, byte[] the byte buffer to write to buf, int the offset in the destination buffer to start at offset, int the number of characters to write len)Format a long (treated as unsigned) into a byte buffer (LATIN1 version). |
private static void | formatUnsignedLong0UTF16(long
the unsigned long to format val, int the log2 of the base to format in (4 for hex, 3 for octal, 1 for binary) shift, byte[] the byte buffer to write to buf, int the offset in the destination buffer to start at offset, int the number of characters to write len)Format a long (treated as unsigned) into a byte buffer (UTF16 version). |
public static Long | |
public static Long | |
public static Long | |
public int | Returns: a hash code value for this object.Overrides java. Returns a hash code for this |
public static int | Returns: a hash code value for along value.the value to hash value)Returns a hash code for a |
public static long | Returns: along 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.the value whose highest one bit is to be computed i)Returns a |
public int | intValue()
Implements abstract java. Returns the value of this |
public long | longValue()
Implements abstract java. Returns the value of this |
public static long | Returns: along 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.the value whose lowest one bit is to be computed i)Returns a |
public static long | |
public static long | |
public static int | Returns: the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specifiedlong value, or 64 if the value
is equal to zero.the value whose number of leading zeros is to be computed i)Returns the number of zero bits preceding the highest-order
("leftmost") one-bit in the two's complement binary representation
of the specified |
public static int | Returns: the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complement binary representation of the specifiedlong value, or 64 if the value is equal
to zero.the value whose number of trailing zeros is to be computed i)Returns the number of zero bits following the lowest-order ("rightmost")
one-bit in the two's complement binary representation of the specified
|
private static long | |
public static long | |
public static long | Returns: the signedlong represented by the subsequence in
the specified radix.the s, int CharSequence containing the long
representation to be parsedthe beginning index, inclusive. beginIndex, int the ending index, exclusive. endIndex, int the radix to be used while parsing radix)s .Parses the |
public static long | |
public static long | Returns: the unsignedlong represented by the string
argument in the specified radix.the s, int String containing the unsigned integer
representation to be parsedthe radix to be used while parsing radix)s .Parses the string argument as an unsigned |
public static long | Returns: the unsignedlong represented by the subsequence in
the specified radix.the s, int CharSequence containing the unsigned
long representation to be parsedthe beginning index, inclusive. beginIndex, int the ending index, exclusive. endIndex, int the radix to be used while parsing radix)s .Parses the |
public static long | Returns: the unsignedlong value represented by the decimal string argumenta s)String containing the unsigned long
representation to be parsedParses the string argument as an unsigned decimal |
public static long | Returns: the unsigned remainder of the first argument divided by the second argumentthe value to be divided dividend, long the value doing the dividing 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. |
public Long | Returns: the Long instanceignored lookupImplements java. Resolves this instance as a |
public static long | Returns: the value obtained by reversing order of the bits in the specifiedlong value.the value to be reversed i)Returns the value obtained by reversing the order of the bits in the
two's complement binary representation of the specified |
public static long | Returns: the value obtained by reversing the bytes in the specifiedlong value.the value whose bytes are to be reversed i)Returns the value obtained by reversing the order of the bytes in the
two's complement representation of the specified |
public static long | Returns: the value obtained by rotating the two's complement binary representation of the specifiedlong value left by the
specified number of bits.the value whose bits are to be rotated left i, int the number of bit positions to rotate left distance)Returns the value obtained by rotating the two's complement binary
representation of the specified |
public static long | Returns: the value obtained by rotating the two's complement binary representation of the specifiedlong value right by the
specified number of bits.the value whose bits are to be rotated right i, int the number of bit positions to rotate right distance)Returns the value obtained by rotating the two's complement binary
representation of the specified |
public short | shortValue()
Overrides java. Returns the value of this |
public static int | Returns: the signum function of the specifiedlong value.the value whose signum is to be computed i)Returns the signum function of the specified |
pack-priv static int | Returns: string sizelong value x)Returns the string representation size for a given long value. |
public static long | Returns: the sum ofa and b the first operand a, long the second operand b)Adds two |
public static String | Returns: the string representation of the unsignedlong
value represented by the argument in binary (base 2).a i)long to be converted to a string.Returns a string representation of the |
public static String | Returns: the string representation of the unsignedlong
value represented by the argument in hexadecimal
(base 16).a i)long to be converted to a string.Returns a string representation of the |
public static String | Returns: the string representation of the unsignedlong
value represented by the argument in octal (base 8).a i)long to be converted to a string.Returns a string representation of the |
public static String | Returns: a string representation of the argument in the specified radix.a i, int long to be converted to a string.the radix to use in the string representation. radix)Returns a string representation of the first argument in the radix specified by the second argument. |
public static String | Returns: a string representation of the argument in base 10.a i)long to be converted.Returns a |
public String | Returns: a string representation of the value of this object in base 10.Overrides java. Returns a |
private static String | |
private static BigInteger | |
public static String | Returns: an unsigned string representation of the argument in the specified radix.an integer to be converted to an unsigned string. i, int the radix to use in the string representation. radix)Returns a string representation of the first argument as an unsigned integer value in the radix specified by the second argument. |
public static String | Returns: an unsigned string representation of the argument.an integer to be converted to an unsigned string. i)Returns a string representation of the argument as an unsigned decimal value. |
pack-priv static String | toUnsignedString0(long
the value to format val, int the log2 of the base to format in (4 for hex, 3 for octal, 1 for binary) shift)Format a long (treated as unsigned) into a String. |
public static Long | Returns: aLong object holding the value
represented by the string argument in the specified
radix.the string to be parsed s, int the radix to be used in interpreting radix)s Returns a |
public static Long | |
public static Long | Returns: aLong instance representing l .a long value. l)Returns a |