Java: parse int value from a char

后端 未结 7 1264
借酒劲吻你
借酒劲吻你 2020-11-22 16:10

I just want to know if there\'s a better solution to parse a number from a character in a string (assuming that we know that the character at index n is a number).



        
7条回答
  •  半阙折子戏
    2020-11-22 16:50

    String element = "el5";
    int x = element.charAt(2) - 48;
    

    Subtracting ascii value of '0' = 48 from char

提交回复
热议问题