如何用java中的另一个值替换String数组值

时间:2015-08-25 04:35:42

标签: java android

String[] Arr_InfraId;   
List<String> List_infraid = new ArrayList<String>();

Arr_InfraId = List_infraid.toArray(new String[List_infraid.size()]); 

这是我的String数组和String数组中的值我分别得到1,2,3,4...10我想分别替换所有值A,B,C,.....j并存储在像1->A,2->b,3->c........10->j这样的String数组中。请告诉我如何替换这个我得到null Pointer exception当我试图获得循环并尝试替换它。

1 个答案:

答案 0 :(得分:1)

public class Main {
static String [] string1 = {
        "1","2",
        "3","4",
        "5","6",
        "7","8",
        "9","10"};

static ArrayList<String> as = new ArrayList<String>();
public static void main(String[] args) {

    for(int i =0;i<string1.length;i++){
        getArray(string1[i]);
    }
    System.out.println(as.toString());
}

public static void  getArray(String string){
    switch (string) {
    case "2":
        as.add("A");
        break;
    case "3":
        as.add("B");
        break;
    case "4":
        as.add("C");
        break;
    case "5":
        as.add("D");
        break;
    case "6":
        as.add("F");
        break;
    case "7":
        as.add("G");
        break;
    case "8":
        as.add("H");
        break;
    case "9":
        as.add("I");
        break;
    case "10":
        as.add("J");
        break;

    default:
        break;
       }
    }
}