I have the following HashMap that I insert character-int pairs in a method and return this hashmap:
HashMap<Character, Integer> hmap = new HashMap<Character, Integer>();
for (...) {
hmap.put(string[i], number[i]);
}
However, when I want to convert this returned hashmap keys to char array, it includes also brackets and commas:
char[] charArray = myReturnedHashMap.keySet().toString().toCharArray();
//it returns 8 char "[ A , B , C , ]" instead of just "A B C"
So, how can I fix it?
Update: On the other hand, I am not sure if HashMap is a good idea to use in this scenario. I have a loop and I just need to return char and int value pairs. Then in the other method I convert char values to a chararray. Any idea?
.toCharArray()on top of the pretty output. What you need to do is iterate on thekeySet()and put them in a char arraytoStringmethod for conversion Instead use thetoArray()method on the Set returned bymyReturnedHashMap.keySet()(Note that this will give you aCharacter[]but if you want/need to convert that to achar[]I'm sure you can find some solution already here on SO.