java.lang
Class Long
java.lang.Object
|
+--java.lang.Number
|
+--java.lang.Long
All Implemented Interfaces:
Comparable, Serializable
Instances of class Long
represent primitive
long
values.
Additionally, this class provides various helper functions and variables
related to longs.
Since:Authors:- Paul Fisher
- John Keiser
- Warren Levy
- Eric Blake <ebb9@email.byu.edu>
MAX_VALUE
public static final long MAX_VALUE
The maximum value a long
can represent is
9223372036854775807 (or 263 - 1).
MIN_VALUE
public static final long MIN_VALUE
The minimum value a long
can represent is
-9223372036854775808L (or -263).
TYPE
public static final Class TYPE
The primitive type long
is represented by this
Class
object.
Since:
Long
public Long(java.lang.String s)
Create a Long
object representing the value of the
argument after conversion to a long
.
Parameters:
Throws:
See Also:
Long
public Long(long value)
Create a Long
object representing the value of the
long
argument.
Parameters:
byteValue
public byte byteValue()
Return the value of this Long
as a byte
.
Returns:
compareTo
public int compareTo(java.lang.Long l)
Compare two Longs numerically by comparing their long
values. The result is positive if the first is greater, negative if the
second is greater, and 0 if the two are equal.
Since:Parameters:
Returns:
compareTo
public int compareTo(java.lang.Object o)
Behaves like compareTo(Long)
unless the Object
is not a Long
.
Since:Parameters:
Returns:
Throws:
See Also:
decode
public static Long decode(java.lang.String str)
Convert the specified
String
into a
Long
.
The
String
may represent decimal, hexadecimal, or
octal numbers.
The extended BNF grammar is as follows:
DecodableString:
( [ -
] 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 15
Finally, the value must be in the range
MIN_VALUE
to
MAX_VALUE
, or an exception is thrown. Note that you cannot
use a trailing 'l' or 'L', unlike in Java source code.
Since:Parameters:
Returns:
- the value of the String as a
Long
Throws:
doubleValue
public double doubleValue()
Return the value of this Long
as a double
.
Returns:
equals
public boolean equals(java.lang.Object obj)
Returns true
if obj
is an instance of
Long
and represents the same long value.
Parameters:
Returns:
- whether these Objects are semantically equal
floatValue
public float floatValue()
Return the value of this Long
as a float
.
Returns:
getLong
public static Long getLong(java.lang.String nm)
Get the specified system property as a Long
. The
decode()
method will be used to interpret the value of
the property.
Parameters:
Returns:
- the system property as a
Long
, or null if the
property is not found or cannot be decoded
Throws:
See Also:
getLong
public static Long getLong(java.lang.String nm, java.lang.Long def)
Get the specified system property as a Long
, or use a
default Long
value if the property is not found or is
not decodable. The decode()
method will be used to
interpret the value of the property.
Parameters:
Returns:
- the value of the system property, or the default
Throws:
See Also:
getLong
public static Long getLong(java.lang.String nm, long val)
Get the specified system property as a Long
, or use a
default long
value if the property is not found or is not
decodable. The decode()
method will be used to interpret
the value of the property.
Parameters:
Returns:
- the value of the system property, or the default
Throws:
See Also:
hashCode
public int hashCode()
Return a hashcode representing this Object. Long
's hash
code is calculated by (int) (value ^ (value >> 32))
.
Returns:
intValue
public int intValue()
Return the value of this Long
as an int
.
Returns:
longValue
public long longValue()
Return the value of this Long
.
Returns:
parseLong
public static long parseLong(java.lang.String s)
Converts the specified String
into a long
.
This function assumes a radix of 10.
Parameters:
Returns:
Throws:
See Also:
parseLong
public static long parseLong(java.lang.String str, int radix)
Converts the specified String
into an int
using the specified radix (base). The string must not be null
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 by
Character.digit(d, radix)
, and must be in the range
0
to radix - 1
. Finally, the result must be
within MIN_VALUE
to MAX_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:
Returns:
- the
String
argument converted to long
Throws:
shortValue
public short shortValue()
Return the value of this Long
as a short
.
Returns:
toBinaryString
public static String toBinaryString(long l)
Converts the long
to a String
assuming it is
unsigned in base 2.
Parameters:
Returns:
- the
String
representation of the argument
toHexString
public static String toHexString(long l)
Converts the long
to a String
assuming it is
unsigned in base 16.
Parameters:
Returns:
- the
String
representation of the argument
toOctalString
public static String toOctalString(long l)
Converts the long
to a String
assuming it is
unsigned in base 8.
Parameters:
Returns:
- the
String
representation of the argument
toString
public String toString()
Converts the Long
value to a String
and
assumes a radix of 10.
Returns:
- the
String
representation
toString
public static String toString(long num)
Converts the long
to a String
and assumes
a radix of 10.
Parameters:
Returns:
- the
String
representation of the argument
See Also:
toString
public static String toString(long num, int radix)
Converts the long
to a String
using
the specified radix (base). If the radix exceeds
Character.MIN_RADIX
or Character.MAX_RADIX
, 10
is used instead. If the result is negative, the leading character is
'-' ('\\u002D'). The remaining characters come from
Character.forDigit(digit, radix)
('0'-'9','a'-'z').
Parameters:
Returns:
- the
String
representation of the argument
valueOf
public static Long valueOf(java.lang.String s)
Creates a new Long
object using the String
,
assuming a radix of 10.
Parameters:
Returns:
Throws:
See Also:
valueOf
public static Long valueOf(java.lang.String s, int radix)
Creates a new Long
object using the String
and specified radix (base).
Parameters:
Returns:
Throws:
See Also:
Long
represent primitivelong
values. Additionally, this class provides various helper functions and variables related to longs.