public class StrToLong { public static void main (String[] args) { String s = "20000"; try { long l = Long.parseLong(s.trim()); System.out.println("long l = " + l); } catch (NumberFormatException e) { System.out.println("NumberFormatException: " + e.getMessage()); } } }