Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.lang.Number
java.lang.Long
Long
represent primitive
long
values.
Additionally, this class provides various helper functions and variables
related to longs.
Field Summary | |
static long |
|
static long |
|
static int |
|
static Class |
|
Constructor Summary | |
|
Method Summary | |
static int |
|
byte |
|
static int |
|
int | |
static Long | |
double |
|
boolean | |
float |
|
static Long | |
static Long | |
static Long | |
int |
|
static long |
|
int |
|
long |
|
static long |
|
static int |
|
static int |
|
static long | |
static long | |
static long |
|
static long |
|
static long |
|
static long |
|
short |
|
static int |
|
static String |
|
static String |
|
static String |
|
String |
|
static String |
|
static String |
|
static Long | |
static Long | |
static Long |
|
Methods inherited from class java.lang.Number | |
byteValue , doubleValue , floatValue , intValue , longValue , shortValue |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public static final long MAX_VALUE
The maximum value along
can represent is 9223372036854775807 (or 263 - 1).
- Field Value:
- 9223372036854775807L
public static final long MIN_VALUE
The minimum value along
can represent is -9223372036854775808L (or -263).
- Field Value:
- -9223372036854775808L
public static final int SIZE
The number of bits needed to represent along
.
- Field Value:
- 64
- Since:
- 1.5
public static final ClassTYPE
The primitive typelong
is represented by thisClass
object.
- Since:
- 1.1
public Long(String s)
Create aLong
object representing the value of the argument after conversion to along
.
- Parameters:
s
- the string to convert
- Throws:
NumberFormatException
- if the String does not contain a long
- See Also:
valueOf(String)
public static int bitCount(long x)
Return the number of bits set in x.
- Parameters:
x
- value to examine
- Since:
- 1.5
public static int compare(long x, long y)
Compares two unboxed long values. The result is positive if the first is greater, negative if the second is greater, and 0 if the two are equal.
- Parameters:
x
- First value to compare.y
- Second value to compare.
- Returns:
- positive int if the first value is greater, negative if the second is greater, and 0 if the two are equal.
- Since:
- 1.7
public int compareTo(Long l)
Compare two Longs numerically by comparing theirlong
values. The result is positive if the first is greater, negative if the second is greater, and 0 if the two are equal.
- Parameters:
l
- the Long to compare
- Returns:
- the comparison
- Since:
- 1.2
public static Long decode(String str)
Convert the specifiedString
into aLong
. TheString
may represent decimal, hexadecimal, or octal numbers.The extended BNF grammar is as follows:
DecodableString: ( [Finally, the value must be in the range-
] DecimalNumber ) | ( [-
] (0x
|0X
|#
) HexDigit { HexDigit } ) | ( [-
]0
{ OctalDigit } ) DecimalNumber: DecimalDigit except '0' { DecimalDigit } DecimalDigit: Character.digit(d, 10) has value 0 to 9 OctalDigit: Character.digit(d, 8) has value 0 to 7 DecimalDigit: Character.digit(d, 16) has value 0 to 15MIN_VALUE
toMAX_VALUE
, or an exception is thrown. Note that you cannot use a trailing 'l' or 'L', unlike in Java source code.
- Parameters:
str
- theString
to interpret
- Returns:
- the value of the String as a
Long
- Throws:
NumberFormatException
- ifs
cannot be parsed as along
NullPointerException
- ifs
is null
- Since:
- 1.2
public double doubleValue()
Return the value of thisLong
as adouble
.
- Overrides:
- doubleValue in interface Number
- Returns:
- the double value
public boolean equals(Object obj)
Returnstrue
ifobj
is an instance ofLong
and represents the same long value.
- Parameters:
obj
- the object to compare
- Returns:
- whether these Objects are semantically equal
public float floatValue()
Return the value of thisLong
as afloat
.
- Overrides:
- floatValue in interface Number
- Returns:
- the float value
public static Long getLong(String nm)
Get the specified system property as aLong
. Thedecode()
method will be used to interpret the value of the property.
- Parameters:
nm
- the name of the system property
- Returns:
- the system property as a
Long
, or null if the property is not found or cannot be decoded
- Throws:
SecurityException
- if accessing the system property is forbidden
- See Also:
System.getProperty(String)
,decode(String)
public static Long getLong(String nm, Long def)
Get the specified system property as aLong
, or use a defaultLong
value if the property is not found or is not decodable. Thedecode()
method will be used to interpret the value of the property.
- Parameters:
nm
- the name of the system propertydef
- the default value
- Returns:
- the value of the system property, or the default
- Throws:
SecurityException
- if accessing the system property is forbidden
- See Also:
System.getProperty(String)
,decode(String)
public static Long getLong(String nm, long val)
Get the specified system property as aLong
, or use a defaultlong
value if the property is not found or is not decodable. Thedecode()
method will be used to interpret the value of the property.
- Parameters:
nm
- the name of the system propertyval
- the default value
- Returns:
- the value of the system property, or the default
- Throws:
SecurityException
- if accessing the system property is forbidden
- See Also:
System.getProperty(String)
,decode(String)
public int hashCode()
Return a hashcode representing this Object.Long
's hash code is calculated by(int) (value ^ (value >> 32))
.
- Returns:
- this Object's hash code
public static long highestOneBit(long value)
Find the highest set bit in value, and return a new value with only that bit set.
- Parameters:
value
- the value to examine
- Since:
- 1.5
public static long lowestOneBit(long value)
Find the lowest set bit in value, and return a new value with only that bit set.
- Parameters:
value
- the value to examine
- Since:
- 1.5
public static int numberOfLeadingZeros(long value)
Return the number of leading zeros in value.
- Parameters:
value
- the value to examine
- Since:
- 1.5
public static int numberOfTrailingZeros(long value)
Find the number of trailing zeros in value.
- Parameters:
value
- the value to examine
- Since:
- 1.5
public static long parseLong(String s)
Converts the specifiedString
into along
. This function assumes a radix of 10.
- Parameters:
s
- theString
to convert
- Returns:
- the
int
value ofs
- Throws:
NumberFormatException
- ifs
cannot be parsed as along
- See Also:
parseLong(String,int)
public static long parseLong(String str, int radix)
Converts the specifiedString
into anint
using the specified radix (base). The string must not benull
or empty. It may begin with an optional '-', which will negate the answer, provided that there are also valid digits. Each digit is parsed as if byCharacter.digit(d, radix)
, and must be in the range0
toradix - 1
. Finally, the result must be withinMIN_VALUE
toMAX_VALUE
, inclusive. Unlike Double.parseDouble, you may not have a leading '+'; and 'l' or 'L' as the last character is only valid in radices 22 or greater, where it is a digit and not a type indicator.
- Parameters:
str
- theString
to convertradix
- the radix (base) to use in the conversion
- Returns:
- the
String
argument converted tolong
- Throws:
NumberFormatException
- ifs
cannot be parsed as along
public static long rotateLeft(long x, int distance)
Rotate x to the left by distance bits.
- Parameters:
x
- the value to rotatedistance
- the number of bits by which to rotate
- Since:
- 1.5
public static long rotateRight(long x, int distance)
Rotate x to the right by distance bits.
- Parameters:
x
- the value to rotatedistance
- the number of bits by which to rotate
- Since:
- 1.5
public short shortValue()
Return the value of thisLong
as ashort
.
- Overrides:
- shortValue in interface Number
- Returns:
- the short value
public static int signum(long x)
Return 1 if x is positive, -1 if it is negative, and 0 if it is zero.
- Parameters:
x
- the value to examine
- Since:
- 1.5
public static String toBinaryString(long l)
Converts thelong
to aString
assuming it is unsigned in base 2.
- Parameters:
l
- thelong
to convert toString
- Returns:
- the
String
representation of the argument
public static String toHexString(long l)
Converts thelong
to aString
assuming it is unsigned in base 16.
- Parameters:
l
- thelong
to convert toString
- Returns:
- the
String
representation of the argument
public static String toOctalString(long l)
Converts thelong
to aString
assuming it is unsigned in base 8.
- Parameters:
l
- thelong
to convert toString
- Returns:
- the
String
representation of the argument
public String toString()
Converts theLong
value to aString
and assumes a radix of 10.
- Returns:
- the
String
representation
public static String toString(long num)
Converts thelong
to aString
and assumes a radix of 10.
- Parameters:
num
- thelong
to convert toString
- Returns:
- the
String
representation of the argument
- See Also:
toString(long,int)
public static String toString(long num, int radix)
Converts thelong
to aString
using the specified radix (base). If the radix exceedsCharacter.MIN_RADIX
orCharacter.MAX_RADIX
, 10 is used instead. If the result is negative, the leading character is '-' ('\\u002D'). The remaining characters come fromCharacter.forDigit(digit, radix)
('0'-'9','a'-'z').
- Parameters:
num
- thelong
to convert toString
radix
- the radix (base) to use in the conversion
- Returns:
- the
String
representation of the argument
public static Long valueOf(String s)
Creates a newLong
object using theString
, assuming a radix of 10.
- Parameters:
s
- theString
to convert
- Returns:
- the new
Long
- Throws:
NumberFormatException
- ifs
cannot be parsed as along
- See Also:
Long(String)
,parseLong(String)
public static Long valueOf(String s, int radix)
Creates a newLong
object using theString
and specified radix (base).
- Parameters:
s
- theString
to convertradix
- the radix (base) to convert with
- Returns:
- the new
Long
- Throws:
NumberFormatException
- ifs
cannot be parsed as along
- See Also:
parseLong(String,int)
public static Long valueOf(long val)
Returns aLong
object wrapping the value.
- Parameters:
val
- the value to wrap
- Returns:
- the
Long
- Since:
- 1.5