Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+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 (1 point)

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 (5.7k points)
–2 votes

If you assign them as variables.

answered by (-499 points)
...