Package java.lang

Class Long

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static long MAX_VALUE
      Constant for the maximum long value, 263-1.
      static long MIN_VALUE
      Constant for the minimum long value, -263.
      static int SIZE
      Constant for the number of bits needed to represent a long in two's complement form.
    • Constructor Summary

      Constructors 
      Constructor Description
      Long​(long value)
      Constructs a new Long with the specified primitive long value.
      Long​(String string)
      Constructs a new Long from the specified string.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static int bitCount​(long v)
      Counts the number of 1 bits in the specified long value; this is also referred to as population count.
      byte byteValue()
      Returns this object's value as a byte.
      static int compare​(long lhs, long rhs)
      Compares two long values.
      int compareTo​(Long object)
      Compares this object to the specified long object to determine their relative order.
      static Long decode​(String string)
      Parses the specified string and returns a Long instance if the string can be decoded into a long value.
      double doubleValue()
      Returns this object's value as a double.
      boolean equals​(Object o)
      Compares this instance with the specified object and indicates if they are equal.
      float floatValue()
      Returns this object's value as a float.
      int hashCode()
      Returns an integer hash code for this object.
      static long highestOneBit​(long v)
      Determines the highest (leftmost) bit of the specified long value that is 1 and returns the bit mask value for that bit.
      int intValue()
      Returns this object's value as an int.
      long longValue()
      Gets the primitive value of this long.
      static long lowestOneBit​(long v)
      Determines the lowest (rightmost) bit of the specified long value that is 1 and returns the bit mask value for that bit.
      static int numberOfLeadingZeros​(long v)
      Determines the number of leading zeros in the specified long value prior to the highest one bit.
      static int numberOfTrailingZeros​(long v)
      Determines the number of trailing zeros in the specified long value after the lowest one bit.
      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.
      static long reverse​(long v)
      Reverses the order of the bits of the specified long value.
      static long reverseBytes​(long v)
      Reverses the order of the bytes of the specified long value.
      static long rotateLeft​(long v, int distance)
      Rotates the bits of the specified long value to the left by the specified number of bits.
      static long rotateRight​(long v, int distance)
      Rotates the bits of the specified long value to the right by the specified number of bits.
      short shortValue()
      Returns this object's value as a short.
      static int signum​(long v)
      Returns the value of the signum function for the specified long value.
      static String toBinaryString​(long l)
      Converts the specified long value into its binary string representation.
      static String toHexString​(long l)
      Converts the specified long value into its hexadecimal string representation.
      String toString()
      Returns a string containing a concise, human-readable description of this object.
      static String toString​(long l)
      Converts the specified long value into its decimal string representation.
      static Long valueOf​(long v)
      Returns a Long instance for the specified long value.
      static Long valueOf​(String string)
      Parses the specified string as a signed decimal long value.
      static Long valueOf​(String string, int radix)
      Parses the specified string as a signed long value using the specified radix.
    • Field Detail

      • MAX_VALUE

        public static final long MAX_VALUE
        Constant for the maximum long value, 263-1.
        See Also:
        Constant Field Values
      • MIN_VALUE

        public static final long MIN_VALUE
        Constant for the minimum long value, -263.
        See Also:
        Constant Field Values
      • SIZE

        public static final int SIZE
        Constant for the number of bits needed to represent a long in two's complement form.
        Since:
        1.5
        See Also:
        Constant Field Values
    • Constructor Detail

      • Long

        public Long​(long value)
        Constructs a new Long with the specified primitive long value.
        Parameters:
        value - the primitive long value to store in the new instance.
    • Method Detail

      • byteValue

        public byte byteValue()
        Description copied from class: Number
        Returns this object's value as a byte. Might involve rounding and/or truncating the value, so it fits into a byte.
        Overrides:
        byteValue in class Number
        Returns:
        the primitive byte value of this object.
      • compareTo

        public int compareTo​(Long object)
        Compares this object to the specified long object to determine their relative order.
        Specified by:
        compareTo in interface Comparable<Long>
        Parameters:
        object - the long object to compare this object to.
        Returns:
        a negative value if the value of this long is less than the value of object; 0 if the value of this long and the value of object are equal; a positive value if the value of this long is greater than the value of object.
        Since:
        1.2
        See Also:
        Comparable
      • compare

        public static int compare​(long lhs,
                                  long rhs)
        Compares two long values.
        Parameters:
        lhs - First value.
        rhs - Second value.
        Returns:
        0 if lhs = rhs, less than 0 if lhs < rhs, and greater than 0 if lhs > rhs.
        Since:
        1.7
      • decode

        public static Long decode​(String string)
                           throws NumberFormatException
        Parses the specified string and returns a Long instance if the string can be decoded into a long value. The string may be an optional minus sign "-" followed by a hexadecimal ("0x..." or "#..."), octal ("0..."), or decimal ("...") representation of a long.
        Parameters:
        string - a string representation of a long value.
        Returns:
        a Long containing the value represented by string.
        Throws:
        NumberFormatException - if string cannot be parsed as a long value.
      • doubleValue

        public double doubleValue()
        Description copied from class: Number
        Returns this object's value as a double. Might involve rounding.
        Specified by:
        doubleValue in class Number
        Returns:
        the primitive double value of this object.
      • 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 of Long and have the same long value as this object.
        Overrides:
        equals in class Object
        Parameters:
        o - the object to compare this long with.
        Returns:
        true if the specified object is equal to this Long; false otherwise.
        See Also:
        Object.hashCode()
      • floatValue

        public float floatValue()
        Description copied from class: Number
        Returns this object's value as a float. Might involve rounding.
        Specified by:
        floatValue in class Number
        Returns:
        the primitive float value of this object.
      • hashCode

        public int hashCode()
        Description copied from class: Object
        Returns an integer hash code for this object. By contract, any two objects for which Object.equals(java.lang.Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

        Note that hash values must not change over time unless information used in equals comparisons also changes.

        See Writing a correct hashCode method if you intend implementing your own hashCode method.

        Overrides:
        hashCode in class Object
        Returns:
        this object's hash code.
        See Also:
        Object.equals(java.lang.Object)
      • intValue

        public int intValue()
        Description copied from class: Number
        Returns this object's value as an int. Might involve rounding and/or truncating the value, so it fits into an int.
        Specified by:
        intValue in class Number
        Returns:
        the primitive int value of this object.
      • longValue

        public long longValue()
        Gets the primitive value of this long.
        Specified by:
        longValue in class Number
        Returns:
        this object's primitive value.
      • 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 - if string cannot 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 using radix.
        Throws:
        NumberFormatException - if string cannot be parsed as a long value, or radix < Character.MIN_RADIX || radix > Character.MAX_RADIX.
      • shortValue

        public short shortValue()
        Description copied from class: Number
        Returns this object's value as a short. Might involve rounding and/or truncating the value, so it fits into a short.
        Overrides:
        shortValue in class Number
        Returns:
        the primitive short value of this object.
      • toBinaryString

        public static String toBinaryString​(long l)
        Converts the specified long value into its binary string representation. The returned string is a concatenation of '0' and '1' characters.
        Parameters:
        l - the long value to convert.
        Returns:
        the binary string representation of v.
      • toHexString

        public static String toHexString​(long l)
        Converts the specified long value into its hexadecimal string representation. The returned string is a concatenation of characters from '0' to '9' and 'a' to 'f'.
        Parameters:
        l - the long value to convert.
        Returns:
        the hexadecimal string representation of l.
      • toString

        public String toString()
        Description copied from class: Object
        Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data.
        Overrides:
        toString in class Object
        Returns:
        a printable representation of this object.
      • 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.
      • valueOf

        public static Long valueOf​(String string)
                            throws NumberFormatException
        Parses the specified string as a signed decimal long value.
        Parameters:
        string - the string representation of a long value.
        Returns:
        a Long instance containing the long value represented by string.
        Throws:
        NumberFormatException - if string cannot be parsed as a long value.
        See Also:
        parseLong(String)
      • valueOf

        public static Long valueOf​(String string,
                                   int radix)
                            throws NumberFormatException
        Parses the specified string as a signed long value using the specified radix.
        Parameters:
        string - the string representation of a long value.
        radix - the radix to use when parsing.
        Returns:
        a Long instance containing the long value represented by string using radix.
        Throws:
        NumberFormatException - if string cannot be parsed as a long value, or radix < Character.MIN_RADIX || radix > Character.MAX_RADIX.
        See Also:
        parseLong(String, int)
      • highestOneBit

        public static long highestOneBit​(long v)
        Determines the highest (leftmost) bit of the specified long value that is 1 and returns the bit mask value for that bit. This is also referred to as the Most Significant 1 Bit. Returns zero if the specified long is zero.
        Parameters:
        v - the long to examine.
        Returns:
        the bit mask indicating the highest 1 bit in v.
        Since:
        1.5
      • lowestOneBit

        public static long lowestOneBit​(long v)
        Determines the lowest (rightmost) bit of the specified long value that is 1 and returns the bit mask value for that bit. This is also referred to as the Least Significant 1 Bit. Returns zero if the specified long is zero.
        Parameters:
        v - the long to examine.
        Returns:
        the bit mask indicating the lowest 1 bit in v.
        Since:
        1.5
      • numberOfLeadingZeros

        public static int numberOfLeadingZeros​(long v)
        Determines the number of leading zeros in the specified long value prior to the highest one bit.
        Parameters:
        v - the long to examine.
        Returns:
        the number of leading zeros in v.
        Since:
        1.5
      • numberOfTrailingZeros

        public static int numberOfTrailingZeros​(long v)
        Determines the number of trailing zeros in the specified long value after the lowest one bit.
        Parameters:
        v - the long to examine.
        Returns:
        the number of trailing zeros in v.
        Since:
        1.5
      • bitCount

        public static int bitCount​(long v)
        Counts the number of 1 bits in the specified long value; this is also referred to as population count.
        Parameters:
        v - the long to examine.
        Returns:
        the number of 1 bits in v.
        Since:
        1.5
      • rotateLeft

        public static long rotateLeft​(long v,
                                      int distance)
        Rotates the bits of the specified long value to the left by the specified number of bits.
        Parameters:
        v - the long value to rotate left.
        distance - the number of bits to rotate.
        Returns:
        the rotated value.
        Since:
        1.5
      • rotateRight

        public static long rotateRight​(long v,
                                       int distance)
        Rotates the bits of the specified long value to the right by the specified number of bits.
        Parameters:
        v - the long value to rotate right.
        distance - the number of bits to rotate.
        Returns:
        the rotated value.
        Since:
        1.5
      • reverseBytes

        public static long reverseBytes​(long v)
        Reverses the order of the bytes of the specified long value.
        Parameters:
        v - the long value for which to reverse the byte order.
        Returns:
        the reversed value.
        Since:
        1.5
      • reverse

        public static long reverse​(long v)
        Reverses the order of the bits of the specified long value.
        Parameters:
        v - the long value for which to reverse the bit order.
        Returns:
        the reversed value.
        Since:
        1.5
      • signum

        public static int signum​(long v)
        Returns the value of the signum function for the specified long value.
        Parameters:
        v - the long value to check.
        Returns:
        -1 if v is negative, 1 if v is positive, 0 if v is zero.
        Since:
        1.5
      • valueOf

        public static Long valueOf​(long v)
        Returns a Long instance for the specified long value.

        Parameters:
        v - the long value to store in the instance.
        Returns:
        a Long instance containing v.
        Since:
        1.5