Long

public final class Long extends Number
implements Comparable<Long>

The 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.

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).

Constant Summary

int BYTES The number of bytes used to represent a long value in two's complement binary form.
long MAX_VALUE A constant holding the maximum value a long can have, 263-1.
long MIN_VALUE A constant holding the minimum value a long can have, -263.
int SIZE The number of bits used to represent a long value in two's complement binary form.

Field Summary

public static final Class<Long> TYPE The Class instance representing the primitive type long.

Public Constructor Summary

Long(long value)
Constructs a newly allocated Long object that represents the specified long argument.
Long(String s)
Constructs a newly allocated Long object that represents the long value indicated by the String parameter.

Public Method Summary

static int
bitCount(long i)
Returns the number of one-bits in the two's complement binary representation of the specified long value.
byte
byteValue()
Returns the value of this Long as a byte.
static int
compare(long x, long y)
Compares two long values numerically.
int
compareTo(Long anotherLong)
Compares two Long objects numerically.
static Long
decode(String nm)
Decodes a String into a Long.
double
doubleValue()
Returns the value of this Long as a double.
boolean
equals(Object obj)
Compares this object to the specified object.
float
floatValue()
Returns the value of this Long as a float.
static Long
getLong(String nm, Long val)
Returns the long value of the system property with the specified name.
static Long
getLong(String nm)
Determines the long value of the system property with the specified name.
static Long
getLong(String nm, long val)
Determines the long value of the system property with the specified name.
int
hashCode()
Returns a hash code for this Long.
static int
hashCode(long value)
Returns a hash code for a long value; compatible with Long.hashCode().
static long
highestOneBit(long i)
Returns a long value with at most a single one-bit, in the position of the highest-order ("leftmost") one-bit in the specified long value.
int
intValue()
Returns the value of this Long as an int.
long
longValue()
Returns the value of this Long as a long value.
static long
lowestOneBit(long i)
Returns a long value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in the specified long value.
static long
max(long a, long b)
Returns the greater of two long values as if by calling Math.max.
static long
min(long a, long b)
Returns the smaller of two long values as if by calling Math.min.
static int
numberOfLeadingZeros(long i)
Returns the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specified long value.
static int
numberOfTrailingZeros(long i)
Returns the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complement binary representation of the specified long value.
static long
parseLong(String s)
Parses the string argument as a signed decimal long.
static long
parseLong(String s, int radix)
Parses the string argument as a signed long in the radix specified by the second argument.
static long
reverse(long i)
Returns the value obtained by reversing the order of the bits in the two's complement binary representation of the specified long value.
static long
reverseBytes(long i)
Returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified long value.
static long
rotateLeft(long i, int distance)
Returns the value obtained by rotating the two's complement binary representation of the specified long value left by the specified number of bits.
static long
rotateRight(long i, int distance)
Returns the value obtained by rotating the two's complement binary representation of the specified long value right by the specified number of bits.
short
shortValue()
Returns the value of this Long as a short.
static int
signum(long i)
Returns the signum function of the specified long value.
static long
sum(long a, long b)
Adds two long values together as per the + operator.
static String
toBinaryString(long i)
Returns a string representation of the long argument as an unsigned integer in base 2.
static String
toHexString(long i)
Returns a string representation of the long argument as an unsigned integer in base 16.
static String
toOctalString(long i)
Returns a string representation of the long argument as an unsigned integer in base 8.
static String
toString(long i, int radix)
Returns a string representation of the first argument in the radix specified by the second argument.
String