Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Turn a String into a long.  RSS feed

 
Mannie J Chaihan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a String and I need a long.
How can i change a string into a long?

long findtemplong = findtemp.toString(); // obviously does not work.
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use parseLong, look in the API if you're not sure.
 
Adam Altmann
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
long findtemplong = findtemp.toString(); // obviously does not work.


You use .toString to return a String on whatever Object you call it on. Not the other way around.

You want to use the Long wrapper class' static method Long.parseLong(String) to get a long value from a String.
 
Abdulla Mamuwala
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this piece of code, if it helps
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!