java - How do I get an array of keys from a hashmap that aren't type Object? -


iterator = myhashmap.keyset().iterator(); while (it.hasnext()) {    int next = it.next(); } 

that doesn't work because it.next() returns object. hashmap uses ints keys. of methods accept ints access hashmap. how can int value when looping through keys can pass other methods?

you should use generics.

 map<integer, object> myhashmap; 

this gives keys integer (not int, cannot helped). integer can automatically unboxed:

for (int key : myhashmap.keyset()){  } 

if want keys in ascending order, consider using treemap instead of hashmap.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -