Tutorialspoint examples

Learn java tutorial with examples for beginners online

Convert string to long java program


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

package com.tutorialspointexamples;
 
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.tutorialspointexamples;
 
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.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status