Long wrapper class is used to wrap primitive data type long value in an object.
Examples of Long Wrapper Class
Example 1 : Convert long data type value to Long object
public class longToLong
{
public static void main(String[] args)
{
long i = 100;
Long l = new Long(i);
System.out.println(l);
}
}
Output
100
This example shows how a long data type value can be converted to Long object.
Example 2 : Convert String to Long object
public class StringToLong
{
public static void main(String[] args)
{
Long l1 = new Long("123");
System.out.println(l1);
String str = "234";
Long l2 = Long.valueOf(str);
System.out.println(l2);
}
}
Output
123
234
This example shows how we can convert String object to Long object.