Java - Long Class
Introduction
The Java 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.
YPE − This is the class instance representing the primitive type int.
Class constructors
| Sr.No. | Constructor & Description |
|---|---|
| 1 |
Long(long value) This constructs a newly allocated Long object that represents the specified long argument. |
| 2 |
Long(String s) This constructs a newly allocated Long object that represents the long value indicated by the String parameter. |
Class methods
Methods inherited
This class inherits methods from the following classes −
- java.lang.Object
Getting a Long Object from A String Example
The following example shows the usage of Long class to get int from a string.
package com.tutorialspoint;
public class LongDemo {
public static void main(String[] args) {
// create a String s and assign value to it
String s = "+120";
// create a Long object l
Long l;
// get the value of long from string
l = Long.valueOf(s);
// print the value
System.out.println( "Long value of string " + s + " is " + l );
}
}
Output
Let us compile and run the above program, this will produce the following result −
Long value of string +120 is 120
java_lang_double.htm