Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.lang

Class Long

java.lang.Object
|
+--java.lang.Number
   |
   +--java.lang.Long

All Implemented Interfaces:

Comparable, Serializable


public final class Long

extends Number

implements Comparable

Instances of class Long represent primitive long values. Additionally, this class provides various helper functions and variables related to longs.

Since:Authors:

Field Summary

static longMAX_VALUE

The maximum value a long can represent is 9223372036854775807 (or 263 - 1).
static longMIN_VALUE

The minimum value a long can represent is -9223372036854775808L (or -263).
static java.lang.ClassTYPE

The primitive type long is represented by this Class object.

Constructor Summary

Long(long value)

Create a Long object representing the value of the long argument.
Long(java.lang.String s)

Create a Long object representing the value of the argument after conversion to a long.

Method Summary

bytebyteValue()

Return the value of this Long as a byte.
intcompareTo(java.lang.Long l)

Compare two Longs numerically by comparing their long values.
intcompareTo(java.lang.Object o)

Behaves like compareTo(Long) unless the Object is not a Long.
static java.lang.Longdecode(java.lang.String str)

Convert the specified String into a Long.
doubledoubleValue()

Return the value of this Long as a double.
booleanequals(java.lang.Object obj)

Returns true if obj is an instance of Long and represents the same long value.
floatfloatValue()

Return the value of this Long as a float.
static java.lang.LonggetLong(java.lang.String nm)

Get the specified system property as a Long.
static java.lang.LonggetLong(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.
static java.lang.LonggetLong(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.
inthashCode()

Return a hashcode representing this Object.
intintValue()

Return the value of this Long as an int.
longlongValue()

Return the value of this Long.
static longparseLong(java.lang.String str, int radix)

Converts the specified String into an int using the specified radix (base).
static longparseLong(java.lang.String s)

Converts the specified String into a long.
shortshortValue()

Return the value of this Long as a short.
static java.lang.StringtoBinaryString(long l)

Converts the long to a String assuming it is unsigned in base 2.
static java.lang.StringtoHexString(long l)

Converts the long to a String assuming it is unsigned in base 16.
static java.lang.StringtoOctalString(long l)

Converts the long to a String assuming it is unsigned in base 8.
static java.lang.StringtoString(long num, int radix)

Converts the long to a String using the specified radix (base).
static java.lang.StringtoString(long num)

Converts the long to a String and assumes a radix of 10.
java.lang.StringtoString()

Converts the Long value to a String and assumes a radix of 10.
static java.lang.LongvalueOf(java.lang.String s, int radix)

Creates a new Long object using the String and specified radix (base).
static java.lang.LongvalueOf(java.lang.String s)

Creates a new Long object using the String, assuming a radix of 10.

Field Details

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:

Constructor Details

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:


Method Details

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:

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:


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:

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:

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:

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:

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:


toHexString

public static String toHexString(long l)

Converts the long to a String assuming it is unsigned in base 16.

Parameters:

Returns:


toOctalString

public static String toOctalString(long l)

Converts the long to a String assuming it is unsigned in base 8.

Parameters:

Returns:


toString

public String toString()

Converts the Long value to a String and assumes a radix of 10.

Returns:


toString

public static String toString(long num)

Converts the long to a String and assumes a radix of 10.

Parameters:

Returns:

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:


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: