Skip to content

Instantly share code, notes, and snippets.

@ramons03
Created November 27, 2011 19:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramons03/1398030 to your computer and use it in GitHub Desktop.
Save ramons03/1398030 to your computer and use it in GitHub Desktop.
Devuelve el maximo valor de repeticiones de acuerdo a una propiedad del objeto
public static int contarRepetidos(ArrayList<Objeto> a) {
Map<Integer, Integer> freqMap = new HashMap<Integer, Integer>();
for (Objeto obj : a) {
freqMap.put(obj.getValor(), (freqMap.get(obj.getValor()) == null ? 1 : (freqMap.get(obj.getValor()) + 1)));
}
return Collections.max(freqMap.values());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment