Java.lang.Long Class
Java Long Class
Java.lang package provides a Long class which wraps a value of the primitive type long in an object. An object of type Long contains a single field whose type is long.
In addition, this class provides several 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.
Class declaration
The declaration of java.lang.Long class is:
public final class Long extends Number implements Comparable<Long>
Fields
S.N | Fields & Description |
---|---|
1. |
static int BYTES The number of bytes used to represent a long value in two's complement binary form. |
2. |
static long MAX_VALUE A constant holding the maximum value a long can have, 263-1. |
3. |
static long MIN_VALUE A constant holding the minimum value a long can have, -263. |
4. |
static int SIZE The number of bits used to represent a long value in two's complement binary form. |
5. |
static Class<Long> TYPE The Class instance representing the primitive type long. |
java.lang.Long Methods
The java.lang.Long class has a number of methods which are listed below:
Member Methods
S.N | Methods & Description |
---|---|
1. |
static int bitCount(long i) Returns the number of one-bits in the two's complement binary representation of the specified long value. |
2. |
byte byteValue() Returns the value of this Long as a byte after a narrowing primitive conversion. |
3. |
static int compare(long x, long y) Compares two long values numerically. |
4. |
int compareTo(Long anotherLong) Compares two Long objects numerically. |
5. |
static int compareUnsigned(long x, long y) Compares two long values numerically treating the values as unsigned. |
6. |
static Long decode(String nm) Decodes a String into a Long. |
7. |
static long divideUnsigned(long dividend, long divisor) Returns the unsigned quotient of dividing the first argument by the second where each argument and the result is interpreted as an unsigned value. |
8. |
double doubleValue() Returns the value of this Long as a double after a widening primitive conversion. |
9. |
boolean equals(Object obj) Compares this object to the specified object. |
10. |
float floatValue() Returns the value of this Long as a float after a widening primitive conversion. |
11. |
static Long getLong(String nm) Determines the long value of the system property with the specified name. |
12. |
static Long getLong(String nm, long val) Determines the long value of the system property with the specified name. |
13. |
static Long getLong(String nm, Long val) Returns the long value of the system property with the specified name. |
14. |
int hashCode() Returns a hash code for this Long. |
15. |
static int hashCode(long value) Returns a hash code for a long value; compatible with Long.hashCode(). |
16. |
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. |
17. |
int intValue() Returns the value of this Long as an int after a narrowing primitive conversion. |
18. |
long longValue() Returns the value of this Long as a long value. |
19. |
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. |
20. |
static long max(long a, long b) Returns the greater of two long values as if by calling Math.max. |
21. |
static long min(long a, long b) Returns the smaller of two long values as if by calling Math.min. |
22. |
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. |
23. |
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. |
24. |
static long parseLong(String s) Parses the string argument as a signed decimal long. |
25. |
static long parseLong(String s, int radix) Parses the string argument as a signed long in the radix specified by the second argument. |
26. |
static long parseUnsignedLong(String s) Parses the string argument as an unsigned decimal long. |
27. |
static long parseUnsignedLong(String s, int radix) Parses the string argument as an unsigned long in the radix specified by the second argument. |
28. |
static long remainderUnsigned(long dividend, long divisor) Returns the unsigned remainder from dividing the first argument by the second where each argument and the result is interpreted as an unsigned value. |
29. |
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. |
30. |
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. |
31. |
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. |
32. |
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. |
33. |
short shortValue() Returns the value of this Long as a short after a narrowing primitive conversion. |
34. |
static int signum(long i) Returns the signum function of the specified long value. |
35. |
static long sum(long a, long b) Adds two long values together as per the + operator. |
36. |
static String toBinaryString(long i) Returns a string representation of the long argument as an unsigned integer in base 2. |
37. |
static String toHexString(long i) Returns a string representation of the long argument as an unsigned integer in base 16. |
38. |
static String toOctalString(long i) Returns a string representation of the long argument as an unsigned integer in base 8. |
39. |
String toString() Returns a String object representing this Long's value. |
40. |
static String toString(long i) Returns a String object representing the specified long. |
41. |
static String toString(long i, int radix) Returns a string representation of the first argument in the radix specified by the second argument. |
42. |
static String toUnsignedString(long i) Returns a string representation of the argument as an unsigned decimal value. |
43. |
static String toUnsignedString(long i, int radix) Returns a string representation of the first argument as an unsigned integer value in the radix specified by the second argument. |
44. |
static Long valueOf(long l) Returns a Long instance representing the specified long value. |
45. |
static Long valueOf(String s) Returns a Long object holding the value of the specified String. |
46. |
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. |
Methods inherited
This class inherits the methods of following class:
- java.lang.Object
- java.lang.Number