Created
January 15, 2020 01:08
-
-
Save parzibyte/8bc5b05465b882d05e4b0c577deb0d97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mapa en donde almacenamos la frecuencia. Ver: https://parzibyte.me/blog/2020/01/07/hashmap-java-tutorial-ejemplos/ | |
HashMap<String, Integer> mapaDeFrecuencias = new HashMap<>(); | |
for (String palabra : palabras) { | |
if (mapaDeFrecuencias.containsKey(palabra)) { | |
mapaDeFrecuencias.put(palabra, mapaDeFrecuencias.get(palabra) + 1); | |
} else { | |
mapaDeFrecuencias.put(palabra, 1); | |
} | |
} | |
// Imprimir mapa | |
for (HashMap.Entry<String, Integer> entry : mapaDeFrecuencias.entrySet()) { | |
System.out.printf("Palabra '%s' con frecuencia %d\n", entry.getKey(), entry.getValue()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment