I have a hashmap like this
public HashMap <String,People> valueHashMap = new Hashmap();
Here the key to my HashMap is time in seconds as string, ie I am adding value to hashmap like this
long timeSinceEpoch = System.currentTimeMillis()/1000;
valueHashMap.put(
Integer.toString((int)timeSinceEpoch)
, people_obj
);
Now I want to get all keys in the hashmap into an array list of integer.
ArrayList<Integer> intKeys = valueHashMap.keys()...
Is there any way to do that?
There is no direct way of converting a list of
Strings to a list ofIntegers:Either you need to redefine your
valueHashMaplike this:Or you need to loop:
I would advice you however to use the
Longas key instead:then there would be no casting to
int(and you can use (1) above withLonginstead).