I need to convert python code to equivalent Java code. Python makes life easier for developers by providing many shortcuts. But now I need to port the same thing to Java. I was wondering what would be the equivalent of dict objects in java? I tried using HashMap, but life is hell. First, consider this,
# Nodes is a dictionary -> Key : (Name, Strength) for node, (name, strength) in nodes.items(): nodes[node] = (name, new_strength)
So how do you translate this into Java? To start, I used the HashMap object, so
Map<Integer, List> nodesMap = new HashMap<Integer,List>(); Iterator updateNodeStrengthIterator = nodesMap.entrySet().iterator(); while(updateNodeStrengthIterator.hasNext()){ }
My problem is getting the List part, which contains the name and strength, and then updating the Strength part. Is there any way to do this? Should I consider some other data structure? Please, help.
java python dictionary hashmap
Chantz
source share