我有一张地图
private HashMap<Character, Integer> map;
我想将它转换为数组但是当我这样做/我得到这个:
Entry<Character, Integer> t = map.entrySet().toArray();
**Type mismatch: cannot convert from Object[] to Map.Entry<Character,Integer>**
Entry<Character, Integer>[] t = null;
map.entrySet().toArray(t);
**Exception in thread "main" java.lang.NullPointerException**
Entry<Character, Integer>[] t = new Entry<Character, Integer>[1];
map.entrySet().toArray(t);
**Cannot create a generic array of Map.Entry<Character,Integer>**
Entry<Character, Integer>[] t = null;
t = map.entrySet().toArray(t);
**Exception in thread "main" java.lang.NullPointerException**
那么如何转换HashMap
为Array
? 在其他科目中找到的答案都不起作用。