我有一个字符串比如"243",java里有现成的函数将其转换为int型的243吗?

解决方案 »

  1.   

    You can take the result by two method as follows.BTW, make sure the String you supply is parseable, otherwise it will throw a NumberFormatException,of course you can handle it with your code.String s = "243";
    int i = Integer.valueOf(s).intValue();
    int i2 = Integer.parseInt(s);
      

  2.   

    You can take the result by two methods as follows.BTW, make sure the String you supply is parseable, otherwise it will throw a NumberFormatException,of course you can handle it with your code.String s = "243";
    int i = Integer.valueOf(s).intValue();
    int i2 = Integer.parseInt(s);
      

  3.   

    String s = "243";
    try
    {
    int i2 = Integer.parseInt(s);
    }
    catch
    {
    }