I'm trying to put together a hashmap with a char array as the value and a string as the key. I'm trying to print out the Keys and Values but keep getting an array out of bounds exception. I'm not sure what the problem is. (Also I might be trying to print out the map incorrectly; I'm kind of just going off other posts). Can someone help me out with the logic of this. Thanks for any help. Here is my code:
public class MapExample {
public static void main(String[] args) {
Map<String,char[]> mp=new HashMap<String, char[]>();
char[] words = new char[2];
words[0] = 'a';
words[1] = 'b';
words[2] = 'c';
mp.put("1", words);
mp.put("2", words);
mp.put("3", words);
Set s=mp.entrySet();
Iterator it=s.iterator();
while(it.hasNext())
{
Map.Entry m =(Map.Entry)it.next();
int key=(Integer)m.getKey();
String value=(String)m.getValue();
System.out.println("Key :"+key+" Value :"+value);
}
}
}