String to long in java

Java convert string to long using Long.parseLong() method

package com.w3spoint;
 
public class StringToLong {
  public static void main(String args[]){
      String str = "578115";
      //convert string to long
      long num = Long.parseLong(str);
      System.out.println(num);
  }
}

Output:

578115

Download this example.

Java convert string to long using Long.valueOf() method

package com.w3spoint;
 
public class StringToLong {
  public static void main(String args[]){
      String str = "578115";
      //convert string to long
      long num = Long.valueOf(str);
      System.out.println(num);
  }
}

Output:

578115

Download this example.

Content Protection by DMCA.com
Please Share