java.lang.Long
java.lang.Number
None
None
JDK 1.0 or later
The Long class provides an object wrapper for a long value. This is useful when you need to treat a long value as an object. For example, there are a number of utility methods that take a reference to an Object as one of their arguments. You cannot specify a long value for one of these arguments, but you can provide a reference to a Long object that encapsulates the long value. Furthermore, as of JDK 1.1, the Long class is necessary to support the Reflection API and class literals.
The Long class also provides a number of utility methods for converting long values to other primitive types and for converting long values to strings and vice versa.
public final class java.lang.Long extends java.lang.Number { // Constants public static final long MIN_VALUE; public static final long MAX_VALUE; public final static Class TYPE; // New in 1.1 // Constructors public Long(long value); public Long(String s); // Class Methods public static Long getLong(String nm); public static Long getLong(String nm, long val); public static Long getLong(String nm, Long val); public static long parseLong(String s); public static long parseLong(String s, int radix); public static String toBinaryString(long i); public static String toHexString(long i); public static String toOctalString(long i); public static String toString(long i); public static String toString(long i, int radix); public static Long valueOf(String s); public static Long valueOf(String s, int radix); // Instance Methods public byte byteValue(); // New in 1.1 public double doubleValue(); public boolean equals(Object obj); public float floatValue(); public int hashCode(); public int intValue(); public long longValue(); public short shortValue(); // New in 1.1 public String toString(); }
The largest value that can be represented by a long.
The smallest value that can be represented by a long.
New as of JDK 1.1
The Class object that represents the type long. It is always true that Long.TYPE == long.class.
The long value to be encapsulated by this object.
Creates a Long object with the specified long value.
The string to be made into a Long object.
If the sequence of characters in the given String does not form a valid long literal.
Constructs a Long object with the value specified by the given string. The string should consist of one or more digit characters. The digit characters can be preceded by a single `-' character. If the string contains any other characters, the constructor throws a NumberFormatException.
The name of a system property.
The value of the system property as a Long object or a Long object with the value 0 if the named property does not exist or cannot be parsed.
This method retrieves the value of the named system property and returns it as a Long object. The method obtains the value of the system property as a String using System.getProperty().
If the value of the property begins with 0x or # and is not followed by a minus sign, the rest of the value is parsed as a hexadecimal integer. If the value begins with 0, it's parsed as an octal integer; otherwise it's parsed as a decimal integer.
The name of a system property.
A default value for the property.
The value of the system property as a Long object or a Long object with the value val if the named property does not exist or cannot be parsed.
This method retrieves the value of the named system property and returns it as a Long object. The method obtains the value of the system property as a String using System.getProperty().
If the value of the property begins with 0x or # and is not followed by a minus sign, the rest of the value is parsed as a hexadecimal integer. If the value begins with 0, it's parsed as an octal integer; otherwise it's parsed as a decimal integer.
The name of a system property.
A default value for the property.
The value of the system property as a Long object, or the Long object val if the named property does not exist or cannot be parsed.
This method retrieves the value of the named system property and returns it as a Long object. The method obtains the value of the system property as a String using System.getProperty().
If the value of the property begins with 0x or # and is not followed by a minus sign, the rest of the value is parsed as a hexadecimal integer. If the value begins with 0, it's parsed as an octal integer; otherwise it's parsed as a decimal integer.
public static long parseLong(String s) throws NumberFormatException
The String to be converted to a long value.
The numeric value of the long represented by the String object.
If the String does not contain a valid representation of a long value.
This method returns the numeric value of the long represented by the contents of the given String object. The String must contain only decimal digits, except that the first character may be a minus sign.
public static long parseLong(String s, int radix) throws NumberFormatException
The String to be converted to a long value.
The radix used in interpreting the characters in the String as digits. It must be in the range Character.MIN_RADIX to Character.MAX_RADIX. If radix is in the range 2 through 10, only characters for which the Character.isDigit() method returns true are considered valid digits. If radix is in the range 11 through 36, characters in the ranges `A' through `Z' and `a' through `z' may be considered valid digits.
The numeric value of the long represented by the String object in the specified radix.
If the String does not contain a valid representation of a long or radix is not in the appropriate range.
This method returns the numeric value of the long represented by the contents of the given String object in the specified radix. The String must contain only valid digits of the specified radix, except that the first character may be a minus sign. The digits are parsed in the specified radix to produce the numeric value.
The long value to be converted to a string.
A string that contains the binary representation of the given value.
This method returns a String object that contains the representation of the given value as an unsigned binary number. To convert the given value to an unsigned quantity, the method simply uses the value as if it were not negative. In other words, if the given value is negative, the method adds 2^64 to it. Otherwise the value is used as it is.
The string returned by this method contains a sequence of one or more `0' and `1' characters. The method returns "0" if its argument is 0. Otherwise, the string returned by this method begins with `1'.
The long value to be converted to a string.
A string that contains the hexadecimal representation of the given value.
This method returns a String object that contains the representation of the given value as an unsigned hexadecimal number. To convert the given value to an unsigned quantity, the method simply uses the value as if it were not negative. In other words, if the given value is negative, the method adds 2^64 to it. Otherwise the value is used as it is.
The string returned by this method contains a sequence of one or more of the characters `0', `1', `2', `3', `4', `5', `6', `7', `8', `9', `a', `b', `c', `d', `e', and `f'. The method returns "0" if its argument is 0. Otherwise, the string returned by this method does not begin with `0'.
To produce a string that contains upper- instead of lowercase letters, use the String.toUpperCase() method.
The long value to be converted to a string.
A string that contains the octal representation of the given value.
This method returns a String object that contains a representation of the given value as an unsigned octal number. To convert the given value to an unsigned quantity, the method simply uses the value as if it were not negative. In other words, if the given value is negative, the method adds 2^64 to it. Otherwise the value is used as it is.
The string returned by this method contains a sequence of one or more of the characters `0', `1', `2', `3', `4', `5', `6', and `7'. The method returns "0" if its argument is 0. Otherwise, the string returned by this method does not begin with `0'.
The long value to be converted to a string.
The string representation of the given value.
This method returns a String object that contains the decimal representation of the given value.
This method returns a string that begins with `-' if the given value is negative. The rest of the string is a sequence of one or more of the characters `0', `1', `2', `3', `4', `5', `6', `7', `8', and `9'. This method returns "0" if its argument is 0. Otherwise, the string returned by this method does not begin with "0" or "-0".
The long value to be converted to a string.
The radix used in converting the value to a string. This value must be in the range Character.MIN_RADIX to Character.MAX_RADIX.
The string representation of the given value in the specified radix.
This method returns a String object that contains the representation of the given value in the specified radix.
This method returns a string that begins with`-' if the given value is negative. The rest of the string is a sequence of one or more characters that represent the magnitude of the given value. The characters that can appear in the sequence are determined by the value of radix. If N is the value of radix, the first N characters on the following line can appear in the sequence:
0123456789abcdefghijklmnopqrstuvwxyz
The method does not verify that radix is in the proper range. If radix is less than Character.MIN_RADIX or greater than Character.MAX_RADIX, the value 10 is used instead of the given value.
This method returns "0" if its argument is 0. Otherwise, the string returned by this method does not begin with "0" or "-0".
public static Long valueOf(String s) throws NumberFormatException
The string to be made into a Long object.
The Long object constructed from the string.
If the String does not contain a valid representation of a long.
Constructs a Long object with the value specified by the given string. The string should consist of one or more digit characters. The digit characters can be preceded by a single - character. If the string contains any other characters, the method throws a NumberFormatException.
public static Long valueOf(String s, int radix) throws NumberFormatException
The string to be made into a Long object.
The radix used in converting the string to a value. This value must be in the range Character.MIN_RADIX to Character.MAX_RADIX.
The Long object constructed from the string.
If the String does not contain a valid representation of a long.
Constructs a Long object with the value specified by the given string in the specified radix. The string should consist of one or more digit characters or characters in the range `A' to `Z' or `a' to `z' that are considered digits in the given radix. The digit characters can be preceded by a single `-' character. If the string contains any other characters, the method throws a NumberFormatException.
The method does not verify that radix is in the proper range. If radix is less than Character.MIN_RADIX or greater than Character.MAX_RADIX, the value 10 is used instead of the given value.
New as of JDK 1.1
The value of this object as a byte.
Number.byteValue()
This method returns the value of this object as a byte. The high order bits of the value are discarded.
The value of this object as a double.
Number.doubleValue()
This method returns the value of this object as a double. Rounding may occur.
The object to be compared with this object.
true if the objects are equal; false if they are not.
Object.equals()
This method returns true if obj is an instance of Long and it contains the same value as the object this method is associated with.
The value of this object as a float.
Number.floatValue()
This method returns the value of this object as a float. Rounding may occur.
A hashcode based on the long value of the object.
Object.hashCode()
This method returns a hashcode computed from the value of this object. More specifically, the result is the exclusive OR of the two halves of the long value represented by the object. If value is the value of the object, the method returns a result equivalent to the following expression:
(int)(value^(value>>>32))
The value of this object as an int.
Number.intValue()
This method returns the value of this object as an int. The high-order bits of the value are discarded.
The value of this object as a long.
Number.longValue()
This method returns the value of this object as a long.
New as of JDK 1.1
The value of this object as a short.
Number.shortValue()
This method returns the value of this object as a short. The high-order bits of the value are discarded.
The string representation of the value of this object.
Object.toString()
This method returns a String object that contains the decimal representation of the value of this object.
This method returns a string that begins with `-' if the value is negative. The rest of the string is a sequence of one or more of the characters `0', `1', `2', `3', `4', `5', `6', `7', `8', and `9'. This method returns "0" if the value of the object is 0. Otherwise, the string returned by this method does not begin with "0" or "-0".
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
finalize() |
Object |
getClass() |
Object |
notify() |
Object |
notifyAll() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
Character; Class; Exceptions; Integer; Integer literals; Integer types; Number; String; System
This HTML Help has been published using the chm2web software. |