Parse a string to int.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tekt9t9
    New Member
    • Jun 2010
    • 2

    Parse a string to int.

    Hello

    I want to parse a string which holds a integer value to an int. The Interger.parsei nt() throws an exception. e.g

    If i try to execute the following code:

    Code:
    i = Integer.parseInt("14141414141414");
    it throws the following exception:
    Code:
    Exception in thread "main" java.lang.NumberFormatException: For input string: "14141414141414"
    	at java.lang.NumberFormatException.forInputString(Unknown Source)
    	at java.lang.Integer.parseInt(Unknown Source)
    	at java.lang.Integer.parseInt(Unknown Source)
    	at CoversionMethod.Konvert(CoversionMethod.java:40)
    	at Converter.main(Converter.java:12)
    However:
    Code:
    i = Integer.parseInt("1414141414");
    with only 10 characters as argument it computes fine. But i need it to parse 14 characters
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    You can use long if you want.

    Regards
    Dheeraj Joshi

    Comment

    • tekt9t9
      New Member
      • Jun 2010
      • 2

      #3
      Thanks that did the work... Quite obvious :-)

      Comment

      Working...