Get Value to Integer

This question already has an answer here:

  • How do I convert a String to an int in Java? 30 answers

  • You can use Integer.valueOf() or Integer.parseInt(); unless there's more to your question that would be something like this -

    public static void main(String[] args) {
      String str = "1";
      int a = Integer.valueOf(str);                 // java.lang.Integer return(ed)
      int b = Integer.parseInt(str);                // primitive (int) return(ed)
      System.out.printf("a = %d, b = %dn", a, b);
    }
    

    On my machine, running this gives

    a = 1, b = 1
    
    链接地址: http://www.djcxy.com/p/20912.html

    上一篇: 我可以读取一个字符串,然后将其用作整数?

    下一篇: 获得整数值