How does Integer.parseInt(string) actually work?

后端 未结 7 1818
南笙
南笙 2020-12-02 20:43

Was asked this question recently and did not know the answer. From a high level can someone explain how Java takes a character / String and convert it into an int.

M

7条回答
  •  北海茫月
    2020-12-02 21:06

    I'm not sure what you're looking for, as "high level". I'll give it a try:

    • take the String, parse all characters one by one
    • start with a total of 0
    • if it is between 0 and 9, total = (total x 10) + current
    • when done, the total is the result

提交回复
热议问题