Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Casting a String into an int?

+7 votes
In my nifty project I casted my integers into Strings using, for example-

userTotal = String.valueOf(userCard1 + userCard2 + userCard3);

but now I need them to be integers again and I do not know how to do it. Please help.
asked Oct 27, 2016 in CSC 211 (F16) by Rachel Cheval (100 points)

1 Answer

+6 votes

You can use either of these two methods:

int num = Integer.valueOf(someString);

or  

int num = Integer.parseInt(someString);

answered Oct 27, 2016 by Forrest Stonedahl (3,438 points)
...