How to simulate Pythons's dict "items()" method for Java's HashMaps? -


i know should learn how program efficiently in java , stop thinking python; problem kind of thing turning out small nightmare in java.

i have following function in python takes string argument:

def decodel(input): l = [] in range(len(input)):     j in x.items(): // "x" dictionary outside function.         if input[i].lower() in j[0]:             l.append(j[1]) return l 

ignoring functionality of function itself, makes work "items()" method, returns me tuples inside of list. can see, play these tuples acessing own indexes.

in java unpleasant problem.

static arraylist items(hashmap hashtarget) {     arraylist l = new arraylist();     set<string> keys = hashtarget.keyset();     collection<object> values = hashtarget.values();      (int = 0; < hashtarget.size(); i++) {         l.add(keys);         l.add(values);     }      return l; } 

as can see, tried implement own "items()" method , failed miserably; since there no tuples natively in java, messing brain :). can't intercalate keys , values in same way python beautifully; therefore, can't create java version of "decodel" function, final goal.

so, that's it; random "challenge" guys.

java has implemented in way of map.entryset() method.

for(map.entry<k, v> j : x.entryset()) {     v val = j.getvalue(); // j[1]     k key = j.getkey();   // j[0] } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -