Parse String to Long and catch exception - Java java.lang

Java examples for java.lang:long Parse

Description

Parse String to Long and catch exception

Demo Code

public class Main {

  public static void main(String[] argv) {
    String obj = "123";
    System.out.println(toLong(obj));
  }// ww w  .ja va 2s  .  co m

  public static long toLong(String obj) {
    try {
      return Long.parseLong(obj);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return 0;
  }

}

Related Tutorials