Java.lang.Long Class

Java.lang.Long Class

Introduction

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.

Class declaration

Following is the declaration for java.lang.Long class:

public final class Long
  extends Number
    implements Comparable<Long>

Field

Following are the fields for java.lang.Long class:

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

Class constructors

S.N.Constructor & Description
1Long(long value)

This constructs a newly allocated Long object that represents the specified long argument.

2Long(String s)

This constructs a newly allocated Long object that represents the long value indicated by the String parameter.

Class methods

S.N.Method & Description
1static int bitCount(long i)

This method returns the number of one-bits in the two’s complement binary representation of the specified long value.

2byte byteValue()

This method returns the value of this Long as a byte.

3int compareTo(Long anotherLong)

This method compares two Long objects numerically.

4static Long decode(String nm)

This method decodes a String into a Long.

5double doubleValue()

This method returns the value of this Long as a double.

6boolean equals(Object obj)

This method compares this object to the specified object.

7float floatValue()

This method returns the value of this Long as a float.

8static Long getLong(String nm)

This method determines the long value of the system property with the specified name.

9static Long getLong(String nm, long val)

This method determines the long value of the system property with the specified name.

10static Long getLong(String nm, Long val)

This method returns the long value of the system property with the specified name.

11int hashCode()

This method returns a hash code for this Long.

12static long highestOneBit(long i)

This method 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.

13int intValue()

This method returns the value of this Long as an int.

14long longValue()

This method returns the value of this Long as a long value.

15static long lowestOneBit(long i)

This method 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.

16static int numberOfLeadingZeros(long i)

This method 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.

17static int numberOfTrailingZeros(long i)

This method 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.

18static long parseLong(String s)

This method parses the string argument as a signed decimal long.

19static long parseLong(String s, int radix)

This method parses the string argument as a signed long in the radix specified by the second argument.

20static long reverse(long i)

This method returns the value obtained by reversing the order of the bits in the two’s complement binary representation of the specified long value.

21static long reverseBytes(long i)

This method returns the value obtained by reversing the order of the bytes in the two’s complement representation of the specified long value.

22static long rotateLeft(long i, int distance)

This method returns the value obtained by rotating the two’s complement binary representation of the specified long value left by the specified number of bits.

23static long rotateRight(long i, int distance)

This method returns the value obtained by rotating the two’s complement binary representation of the specified long value right by the specified number of bits.

24short shortValue()

This method returns the value of this Long as a short.

25static int signum(long i)

This method returns the signum function of the specified long value.

26static String toBinaryString(long i)

This method returns a string representation of the long argument as an unsigned integer in base 2.

27static String toHexString(long i)

This method returns a string representation of the long argument as an unsigned integer in base 16.

28static String toOctalString(long i)

This method returns a string representation of the long argument as an unsigned integer in base 8.

29String toString()

This method returns a String object representing this Long’s value.

30static String toString(long i)

This method returns a String object representing the specified long.

31static String toString(long i, int radix)

This method returns a string representation of the first argument in the radix specified by the second argument.

32static Long valueOf(long l)

This method returns a Long instance representing the specified long value.

33static Long valueOf(String s)

This method returns a Long object holding the value of the specified String.

34static Long valueOf(String s, int radix)

This method returns a Long object holding the value extracted from the specified String when parsed with the radix given by the second argument.

Methods inherited

This class inherits methods from the following classes:

  • java.lang.Object

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.