import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.TreeSet;
import java.util.Scanner;
public class Exercicio {
public static void main(String[] args) {
Map<String, Integer> myMap = new HashMap<String, Integer>();
createMap(myMap);
displayMap(myMap);
}
private static void createMap(Map<String, Integer> map) {
Scanner scanner = new Scanner(System.in);
System.out.println("Digite uma string:");
String input = scanner.nextLine();
String[] tokens = input.split(" ");
for (String token : tokens) {
String word = token.toLowerCase();
token = token.replaceAll(word, token);
if (map.containsKey(word)) {
int count = map.get(word);
map.put(word, count + 1);
} else
map.put(word, 1);
}
scanner.close();
}
private static void displayMap(Map<String, Integer> map) {
Set keys = map.keySet();
TreeSet sortedKeys = new TreeSet(keys);
System.out.println("\nMapa contém:\nChave\t\tValor");
for (String key : sortedKeys)
System.out.printf("%-10s%10s\n", key, map.get(key));
System.out.printf("\ntamanho: %d\nestá vazio: %b\n", map.size(), map.isEmpty());
}
}