定义一个方法,它将转换arraylist的所有String值
整数.
private ArrayList getIntegerArray(ArrayList stringArray) {
ArrayList result = new ArrayList();
for(String stringValue : stringArray) {
try {
//Convert String to Integer, and store it into integer array list.
result.add(Integer.parseInt(stringValue));
} catch(NumberFormatException nfe) {
//System.out.println("Could not parse " + nfe);
Log.w("NumberFormat", "Parsing failed! " + stringValue + " can not be an integer");
}
}
return result;
}
简单地称之为该方法
ArrayList resultList = getIntegerArray(strArrayList); //strArrayList is a collection of Strings as you defined.
快乐编码:)