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.


+14 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 (725 points)

2 Answers

+4 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 (4.5k points)
–1 vote

If you assign them as variables.

answered ago by (2.6k points)