java.lang.Long Class & Methods


The java.lang.Long class wraps a value of the primitive type long in an object. An object of type Long contains a single field whose type is long.
This class provides several utility methods for converting a long to a String and a String to a long, as well as other constants and methods useful when dealing with a long.

Long class implements Comparable Interface that’s help while sorting list of Objects on natural order.

See Also:

Constants

  • static long MAX_VALUE :A constant holding the maximum value a long can have, 263-1.
  • static long MIN_VALUE :A constant holding the minimum value a long can have, -263.
  • static int SIZE :The number of bits used to represent a long value in two’s complement binary form.
  • static Class TYPE :The Class instance representing the primitive type long.

Constructors

  • Long(long value) :Constructs a newly allocated Long object that represents the specified long argument.
  • Long(String s) :Constructs a newly allocated Long object that represents the long value indicated by the String parameter.

Methods

  • static int bitCount(long i) :Returns the number of one-bits in the two’s complement binary representation of the specified long value.
  • byte byteValue() :Returns the value of this Long as a byte.
  • static int compare(long x, long y) :Compares two long values numerically.
  • int compareTo(Long anotherLong) :Compares two Long objects numerically.
  • static Long decode(String nm) :Decodes a String into a Long.
  • double doubleValue() :Returns the value of this Long as a double.
  • boolean equals(Object obj) :Compares this object to the specified object.
  • float floatValue() :Returns the value of this Long as a float.
  • static Long getLong(String nm) :Determines the long value of the system property with the specified name.
  • static Long getLong(String nm, long val) :Determines the long value of the system property with the specified name.
  • static Long getLong(String nm, Long val) :Returns the long value of the system property with the specified name.
  • int hashCode() :Returns a hash code for this Long.
  • static long highestOneBit(long i) :Returns a long value with at most a single one-bit, in the position of the highest-order (“leftmost”) one-bit in the specified long value.
  • int intValue() :Returns the value of this Long as an int.
  • long longValue() :Returns the value of this Long as a long value.
  • static long lowestOneBit(long i) :Returns a long value with at most a single one-bit, in the position of the lowest-order (“rightmost”) one-bit in the specified long value.
  • static int numberOfLeadingZeros(long i) :Returns the number of zero bits preceding the highest-order (“leftmost”) one-bit in the two’s complement binary representation of the specified long value.
  • static int numberOfTrailingZeros(long i) :Returns the number of zero bits following the lowest-order (“rightmost”) one-bit in the two’s complement binary representation of the specified long value.
  • static long parseLong(String s) :Parses the string argument as a signed decimal long.
  • static long parseLong(String s, int radix) :Parses the string argument as a signed long in the radix specified by the second argument.
  • static long reverse(long i) :Returns the value obtained by reversing the order of the bits in the two’s complement binary representation of the specified long value.
  • static long reverseBytes(long i) :Returns the value obtained by reversing the order of the bytes in the two’s complement representation of the specified long value.
  • static long rotateLeft(long i, int distance) :Returns the value obtained by rotating the two’s complement binary representation of the specified long value left by the specified number of bits.
  • static long rotateRight(long i, int distance) :Returns the value obtained by rotating the two’s complement binary representation of the specified long value right by the specified number of bits.
  • short shortValue() :Returns the value of this Long as a short.
  • static int signum(long i) :Returns the signum function of the specified long value.
  • static String toBinaryString(long i) :Returns a string representation of the long argument as an unsigned integer in base 2.
  • static String toHexString(long i) :Returns a string representation of the long argument as an unsigned integer in base 16.
  • static String toOctalString(long i) :Returns a string representation of the long argument as an unsigned integer in base 8.
  • String toString() :Returns a String object representing this Long’s value.
  • static String toString(long i) :Returns a String object representing the specified long.
  • static String toString(long i, int radix) :Returns a string representation of the first argument in the radix specified by the second argument.
  • static Long valueOf(long l) :Returns a Long instance representing the specified long value.
  • static Long valueOf(String s) :Returns a Long object holding the value of the specified String.
  • static Long valueOf(String s, int radix) :Returns a Long object holding the value extracted from the specified String when parsed with the radix given by the second argument.

Exceptions

References

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s