如果键未知,是否有一种优雅的方法可以从 HashMap 中只获得一个 Entry<K,V>
,而不需要迭代。
由于入境顺序并不重要,我们可以这样说吗
hashMapObject.get(zeroth_index);
尽管我知道不存在这样的 get by index 方法。
如果我尝试下面提到的方法,它仍然需要获取散列表的所有条目集。
for(Map.Entry<String, String> entry : MapObj.entrySet()) {
return entry;
}
欢迎提出建议。
编辑: 请建议任何其他数据结构,以满足要求。