java - Why do I get a NumberFormatException when I convert this -


long converted = long.valueof(input); 

input string object.

i want convert string value of number long.

i assumed convert string object, need use .valueof return long object.

is because storing result in primitive variable?

thank help.

if don't provide valid long input throws numberformatexception. see below:

  long converted = long.valueof( "3" );   system.out.println( converted ); 

prints 3

try{     long converted = long.valueof( "test" );     system.out.println( converted ); } catch( numberformatexception e ){     system.out.println( "your input wrong.." ); } 

this throws numberformatexception, it's because not valid number. , prints "your input wrong.."


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -