java.lang
Class Long
- java.lang.Object
-
- java.lang.Long
-
public final class Long extends Object
The wrapper for the primitive typelong
.As with the specification, this implementation relies on code laid out in Henry S. Warren, Jr.'s Hacker's Delight, (Addison Wesley, 2002) as well as The Aggregate's Magic Algorithms.
- Since:
- 1.0
- See Also:
Number
-
-
Field Summary
Fields Modifier and Type Field and Description static long
MAX_VALUE
Constant for the maximumlong
value, 263-1.static long
MIN_VALUE
Constant for the minimumlong
value, -263.
-
Constructor Summary
Constructors Constructor and Description Long(long value)
Constructs a newLong
with the specified primitive long value.
-
Method Summary
Methods Modifier and Type Method and Description boolean
equals(Object o)
Compares this instance with the specified object and indicates if they are equal.int
hashCode()
Returns an integer hash code for this long.long
longValue()
Gets the primitive value of this long.static long
parseLong(String string)
Parses the specified string as a signed decimal long value.static long
parseLong(String string, int radix)
Parses the specified string as a signed long value using the specified radix.String
toString()
Converts this long into its decimal string representation.static String
toString(long l)
Converts the specified long value into its decimal string representation.static String
toString(long l, int radix)
Converts the specified long value into a string representation based on the specified radix.static Long
valueOf(long lng)
Returns aLong
instance for the specified long value.
-
-
-
Field Detail
-
MAX_VALUE
public static final long MAX_VALUE
Constant for the maximumlong
value, 263-1.- See Also:
- Constant Field Values
-
MIN_VALUE
public static final long MIN_VALUE
Constant for the minimumlong
value, -263.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Long
public Long(long value)
Constructs a newLong
with the specified primitive long value.- Parameters:
value
- the primitive long value to store in the new instance.
-
-
Method Detail
-
equals
public boolean equals(Object o)
Compares this instance with the specified object and indicates if they are equal. In order to be equal,o
must be an instance ofLong
and have the same long value as this object.- Overrides:
equals
in classObject
- Parameters:
o
- the object to compare this long with.- Returns:
true
if the specified object is equal to thisLong
;false
otherwise.- See Also:
Object.hashCode()
-
hashCode
public int hashCode()
Returns an integer hash code for this long.- Overrides:
hashCode
in classObject
- Returns:
- this object's hash code.
- See Also:
Object.equals(java.lang.Object)
-
longValue
public long longValue()
Gets the primitive value of this long.- Returns:
- this object's primitive value.
-
toString
public String toString()
Converts this long into its decimal string representation. The returned string is a concatenation of a minus sign if the number is negative and characters from '0' to '9'.
-
toString
public static String toString(long l)
Converts the specified long value into its decimal string representation. The returned string is a concatenation of a minus sign if the number is negative and characters from '0' to '9'.- Parameters:
l
- the long to convert.- Returns:
- the decimal string representation of
l
.
-
toString
public static String toString(long l, int radix)
Converts the specified long value into a string representation based on the specified radix. The returned string is a concatenation of a minus sign if the number is negative and characters from '0' to '9' and 'a' to 'z', depending on the radix. Ifradix
is not in the interval defined byCharacter.MIN_RADIX
andCharacter.MAX_RADIX
then 10 is used as the base for the conversion.- Parameters:
l
- the long to convert.radix
- the base to use for the conversion.- Returns:
- the string representation of
l
.
-
parseLong
public static long parseLong(String string) throws NumberFormatException
Parses the specified string as a signed decimal long value. The ASCII character - ('-') is recognized as the minus sign.- Parameters:
string
- the string representation of a long value.- Returns:
- the primitive long value represented by
string
. - Throws:
NumberFormatException
- ifstring
isnull
, has a length of zero or can not be parsed as a long value.
-
parseLong
public static long parseLong(String string, int radix) throws NumberFormatException
Parses the specified string as a signed long value using the specified radix. The ASCII character - ('-') is recognized as the minus sign.- Parameters:
string
- the string representation of a long value.radix
- the radix to use when parsing.- Returns:
- the primitive long value represented by
string
usingradix
. - Throws:
NumberFormatException
- ifstring
isnull
or has a length of zero,radix < Character.MIN_RADIX
,radix > Character.MAX_RADIX
, or ifstring
can not be parsed as a long value.
-
valueOf
public static Long valueOf(long lng)
Returns aLong
instance for the specified long value.If it is not necessary to get a new
Long
instance, it is recommended to use this method instead of the constructor, since it maintains a cache of instances which may result in better performance.- Parameters:
lng
- the long value to store in the instance.- Returns:
- a
Long
instance containinglng
. - Since:
- 1.5
-
-