Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Madeleine Hughes   on Jul 22 In Java Category.

  
Question Answered By: Cesara Fernandez   on Jul 22

Although you cannot just cast  a String to a long, you
can parse out the value of a String that contains a
number and convert that to a long. You can use the
Long wrapper class and your code would look somewhat
like this:

try
{
String myString = "1234";
long myLong = Long.parseLong(myString);
}
catch (NumberFormatException nfe)
{
// handle the exception however appropriate...
// e.g.
nfe.printStackTrace();
}

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on casting in java Or get search suggestion and latest updates.


Tagged: