pmasiar
April 25th, 2007, 08:00 PM
Java gurus,
I have HashMap nodeIDs (key and value are String). I need to extract keys as Array/list/ArrayList/whatewer
I need to translate to Java Python snippet "ids = nodeIDs.keys()", or to make space for some processing later:
ids = []
for kk in nodeIDs.keys():
ids.append(kk)
I was gogling and strugling and found this (http://forum.java.sun.com/thread.jspa?threadID=540338&messageID=2619891) and this (http://www.dynamicobjects.com/d2r/archives/003033.html) and many more examples, even more confusing :-(
for (Iterator iter = noteIDs.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
String key = (String)entry.getKey();
//String value = (String)entry.getValue();
}
Is this the bast what Java can do, or it's just me being spoiled by Python? Create iterator, and cast to Map.Entry, just to get the darn key?
God, I just love Python!
I have HashMap nodeIDs (key and value are String). I need to extract keys as Array/list/ArrayList/whatewer
I need to translate to Java Python snippet "ids = nodeIDs.keys()", or to make space for some processing later:
ids = []
for kk in nodeIDs.keys():
ids.append(kk)
I was gogling and strugling and found this (http://forum.java.sun.com/thread.jspa?threadID=540338&messageID=2619891) and this (http://www.dynamicobjects.com/d2r/archives/003033.html) and many more examples, even more confusing :-(
for (Iterator iter = noteIDs.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
String key = (String)entry.getKey();
//String value = (String)entry.getValue();
}
Is this the bast what Java can do, or it's just me being spoiled by Python? Create iterator, and cast to Map.Entry, just to get the darn key?
God, I just love Python!