How convert string to long using long wrapper class

How convert string to long using long wrapper class

Previous Home Next

 

This example shows how to convert the string value to the Long.

Long method valueOf is used here to convert the string to the long. 
 ValueOf method of Long class is used to convert string to the Long.

First construct  Long using constructor.then use valueOf method of Long class.This method is static.
The method throw a NumberFormat Exception if the string is not parsed.

 

package Example;

public class Stringlong {


public static void main(String[] args) {

Long Obj1 = new Long("110");
System.out.println(Obj1);
String str = "110";
Long obj2 = Long.valueOf(str);
System.out.println(obj2);



}

}

110
110

Previous Home Next