天天看點

String類型轉化成Int類型

String類型通過ASCII規則轉化成int類型:String–>byte–>int

ArrayList<Integer> arrayList = new ArrayList<Integer>();
ArrayList vecCmdParam = new ArrayList();

for(int i = ; i < vecCmdParam.size(); i++){
    Object object = (Object) vecCmdParam.get(i);
    if(object instanceof String){
        byte[] bytes = ((String) object).getBytes();
        for (int j = ; j < bytes.length; j++){
            arrayList.add((int) bytes[j]);
        }
    }else if (object instanceof Integer){
        arrayList.add((Integer) object);
    }
}