JAVA语言中string类型如何转化成整数类型?

解决方案 »

  1.   

    class A{
      public static void main(String[] args){
        try{
            String s="1";
            int i=Integer.parseInt(s);
            System.out.print(i);
        }catch(NumberFormatException e){
            System.out.print(e);
        }
      }}
      

  2.   

    int x =Integer.parseInt(String);我一般都用这个方法,其实你可以查查API,上面都有的
      

  3.   

    String str1=new String("123");
        Integer I=new Integer(str1);
        System.out.println(I);
      

  4.   

    int a=(new Integer("string")).intValue
      

  5.   

    String STRING = "123";
    int Int = Integer.parseInt(STRING);
      

  6.   

    try {
      int k = Integer.parseInt("123");
    }catch.......
      

  7.   

    andyjt() ( ) 信誉:100  2006-3-13 18:22:55  得分: 0  
     
     
       
    int x =Integer.parseInt(i);-----------------------------------------------------------
    通常我们是用这个,尤其是在读取一个数字的时候。通常根try ...catch
      

  8.   

    try{
        String valueStr = "123";
        int intValue = Integer.parseInt();
    }catch(Exception e){
        System.out.println(e.toString());
    }
      

  9.   

    try{
        String valueStr = "123";
        int intValue = Integer.parseInt(valueStr );
    }catch(Exception e){
        System.out.println(e.toString());
    }
      

  10.   

    多看看帮助文档,里面有很详细的转换方法。包括转为float,double型都是这样。