I think when you use public Object[] toArray() of the Collection interface ,which the HashMap class implements, the returned array is type safe meaning you cannot do a conversion to any type but the Object[] type which is default.
So I would suggest you to use public Object[] toArray(Object[] a) method wherein the specified array the toArray() method takes is the type of the array it returns.
ex- set = (String[])mapa.keySet().toArray(new String[0]);
(or)
set=new String[mapa.ketSet().size];
mapa.keySet().toArray(set);
check out the
java api for the usage of the above method.I hope this info helps.