字符数组如何转换成整型数组?

解决方案 »

  1.   

            private static String[] str;
    public static void main(String arges[]){
      int[] inte = new int[str.length];
      int j = 0;
      for(int i =0; i<str.length;i++){
       String stro = str[i];
       try {
       int t =  Integer.valueOf(stro);
       inte[j] = t;
       j++;
    } catch (Exception e) {
    System.out.println("无法转换成int");
    }
     } 
    }
      

  2.   

    public class TestExchange {
    private static char[] str={'a','b','c','d','e'};
    public static void main(String arges[]){

    int[] inte = new int[str.length];
    int j = 0;
    for(int i =0; i<str.length;i++){
    char c = str[i];
    try {
    int t = Integer.valueOf(c);
    inte[j] = t;
    j++;
    } catch (Exception e) {
    System.out.println("无法转换成int");
    }
    }  
    System.out.println(inte);
    }
    }