【发布时间】:2014-10-13 09:24:23
【问题描述】:
我正在尝试创建一个允许您传入 ArrayList 并返回最大元素的函数。由于传入的数据类型不是原始的,我一直无法找出正确的解决方案。我也尝试将 ArrayList 转换为 ArrayList 但没有成功。到目前为止,这是我的(不正确的)代码:
public static void maxArrayListValue(ArrayList<int[]> arrayList) {
int maxArrayListValue = arrayList.get(0); // set first arrayList element as highest
for (int index=1; index < arrayList.size(); index++) { // cycle through each arrayList element
if (maxArrayListValue < arrayList.get(index)){ // if new element is > than old element
maxArrayListValue = arrayList.get(index); // replace with new maxValue
maxArrayListIndex = index; // record index of max element
}
}
return maxArrayListValue;
}
我们将不胜感激。
【问题讨论】: