I'm doing an exercise and I need to identify an anagram. More or less I have it, but it fails me, because I do not correctly identify the capitals of the lowercase letters and this I do not know very well how to do it.
I have defined a method to put the word to analyze in a TreeMap and in this way I know the letters of the word and the number of times it contains that letter, and so I have it sorted to be able to compare with other words, but It fails me, because it adds quantity regardless of whether the letter is uppercase or lowercase.
The code is
static TreeMap getTreemap(String a){
TreeMap<Character, Integer> mapa = new TreeMap<>();
for (int i = 0;i<a.length(); i++){
Integer valor = mapa.get(a.charAt(i));
if (valor != null){
mapa.put(a.charAt(i), valor+1);
}else{
mapa.put(a.charAt(i), 1);
}
}
return mapa;
}
my problem may come next, when I compare the words here.
if (mapaA.equals(mapaB) != true){
return false;
}else{
return true;
}
Since it tells me that both are equal, although they do not match uppercase or lowercase. Any suggestions to fix it? Thanks.