java - How to convert hashmap to Array of entries -


this question has answer here:

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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -