我需要将 python 代码转换为等效的 java 代码。Python 通过提供许多快捷功能使开发人员的生活变得非常轻松。但现在我需要将其迁移到 Java。我想知道 java 中 dict 对象的等价物是什么?我尝试过使用 HashMap,但生活就是地狱。对于初学者来说,考虑到这一点,
# Nodes is a dictionary -> Key : (Name, Strength)
for node, (name, strength) in nodes.items():
nodes[node] = (name, new_strength)
那么如何将它转换成Java呢?对于初学者,我使用了 HashMap 对象,
Map<Integer, List> nodesMap = new HashMap<Integer,List>();
/* For iterating over the map */
Iterator updateNodeStrengthIterator = nodesMap.entrySet().iterator();
while(updateNodeStrengthIterator.hasNext()){ }
我的问题是获取包含名称和强度的列表部分,然后更新强度部分。有没有可行的方法来做到这一点?我应该考虑一些不同的数据结构吗?请帮忙。