I am not sure exactly on the ways you tried. What I would do is
When you do that you'll get an EntrySet, so the data will be stored as Entry
So if you want to keep it in the EntrySet you can do this:
List<Entry<Character, Integer>> list = new ArrayList<Entry<Character, Integer>>();
for(Entry<Character, Integer> entry : map.entrySet()) {
list.add(entry);
}
Also note that you will always get a different order when doing this, as HashMap isn't ordered.
Or you can do a class to hold the Entry data:
public class Data {
public Character character;
public Integer value;
public Data(Character char, Integer value) {
this.character = character;
this.value = value;
}
}
And extract it using:
List<Data> list = new ArrayList<Data>();
for(Entry<Character, Integer> entry : map.entrySet()) {
list.add(new Data(entry.getKey(), entry.getValue()));
}