java - How to convert hashmap to Array of entries -
this question has answer here:
- how create generic array in java? 27 answers
i have map
private hashmap<character, integer> map;
i want convert array when that/i this:
entry<character, integer> t = map.entryset().toarray(); **type mismatch: cannot convert object[] 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 generic array of map.entry<character,integer>**
entry<character, integer>[] t = null; t = map.entryset().toarray(t); **exception in thread "main" java.lang.nullpointerexception**
so how convert hashmap
array
? none of answers found in other subjects work.
i think work:
entry<character, integer>[] t = (entry<character, integer>[]) (map.entryset().toarray(new map.entry[map.size()]));
... need @suppresswarning annotation suppress warning unsafe typecast.
Comments
Post a Comment