Kri*_*dra 2 java integer hashmap
我有这样的哈希映射
public HashMap <String,People> valueHashMap  = new Hashmap();
这里我的HashMap的关键是以字符串为单位的秒数,即我正在像这样向hashmap添加值
long timeSinceEpoch = System.currentTimeMillis()/1000;
valueHashMap.put(
                   Integer.toString((int)timeSinceEpoch)
                   , people_obj
                );
现在我想将hashmap中的所有键都放入整数数组列表中.
ArrayList<Integer> intKeys = valueHashMap.keys()...
有没有办法做到这一点?
dac*_*cwe 11
没有直接的方法将Strings 列表转换为s列表Integer:
你需要重新定义valueHashMap这样的:
public HashMap<Integer, People> valueHashMap  = new HashMap<Integer, People>();
....
ArrayList<Integer> intKeys = new ArrayList<Integer>(valueHashMap.keySet());
或者你需要循环:
ArrayList<Integer> intKeys = new ArraList<Integer>();
for (String stringKey : valueHashMap.keySet())
     intKeys.add(Integer.parseInt(stringKey);
我会建议你使用Longas键代替:
public HashMap<Long, People> valueHashMap  = new HashMap<Long, People>();
然后就没有施法int (你可以用上面的(1)Long代替).
| 归档时间: | 
 | 
| 查看次数: | 16542 次 | 
| 最近记录: |