Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created January 20, 2020 23:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save parzibyte/cc44f804234680a34c7937927842effb to your computer and use it in GitHub Desktop.
int[] numeros = { 1, 2, 3, 1, 1, 2, 3, 4, 2, 4, 412, 3, 12, 321, 12, 3, 213, 13, 213121, 1, 345, 12, 312, 3, 5424,
314 };
System.out.printf("El arreglo es: %s\n", Arrays.toString(numeros));
HashMap<Integer, Integer> mapa = new HashMap<>();
for (int x = 0; x < numeros.length; x++) {
int numero = numeros[x];
if (mapa.containsKey(numero)) {
mapa.put(numero, mapa.get(numero) + 1);
} else {
mapa.put(numero, 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment