我有一個方法需要一個字符串數組,並根據長度查找每個項目的平均值。我希望該方法根據偏移值刪除數組中的前幾個項目。如何從字符串數組中刪除前幾個項目?
public static double[] getMovingAverage(String[] priceList, int length, int offset){
double[] newPriceList = convert(priceList);
int listLength = newPriceList.length;
int counter = 0;
double listsum;
double[] movingAverage = new double[listLength];
try{
for (int aa = 0; aa < listLength-1; aa++){
listsum = 0;
for (int bb = 0; bb < length; bb++){
counter = aa+bb;
listsum = listsum + newPriceList[counter];
}
movingAverage[aa] = listsum/length;
}
if (offset>0){
//remove first #offset# elements
}
}catch(Exception e){
System.out.println(e);
}
return movingAverage;
}
* note:convert();將String []轉換爲double []
這是一個很好的答案;太糟糕了,在搜索「移位Java數組」時找不到它 - 也許這個評論可能有助於這方面的工作? – lre