Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.


+21 votes

When strings are mixed with numeric values, they will turn numeric values to characters. I am wondering is it possible for the opposite way to happen: a string literal is turned into numeric values (Ex: the string "123456" turn into the number 123456) ?

asked in CSC211_Winter2018 by (8 points)

2 Answers

+11 votes

Indeed there is! You can convert a String into an int like this:

String numberText = "123456";
int number = Integer.parseInt(numberText);

Or there's another way:

int number = Integer.valueOf(numberText);
answered by (10.9k points)
–2 votes

If you assign them as variables.

answered by (253 points)