CodesJava

Easy learning with example program codes

String to long in java


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

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

Please follow and like us:
Posted in Java   


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki