我需要获取对象的arrayList中最常出现的元素的计数.我有这个代码,它正在工作.
public static int contarRepeditos(ArrayList<Objecto> a) {
int resul = 0;
ArrayList<Integer> valores = new ArrayList<Integer>();
for (int i = 0; i < a.size(); i++) {
valores.add(a.get(i).getValor());
}
ArrayList<Integer> resultados = new ArrayList<Integer>();
for (int i = 0; i < valores.size(); i++) {
resultados.add(Collections.frequency(valores, a.get(i).getValor()));
}
resul = Collections.max(resultados);
return resul;
}
Run Code Online (Sandbox Code Playgroud)
我需要知道是否有最好的方法来做到这一点.谢谢.
| 归档时间: |
|
| 查看次数: |
1258 次 |
| 最近记录: |