How to print all key and values from HashMap in Android?
for (Map.Entry<String,String> entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); // do stuff }
for (Map.Entry<String,String> entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); // do stuff }
For Python 3: my_dict2 = {y: x for x, y in my_dict.items()} For Python 2, you can use my_dict2 = dict((y, x) for x, y in my_dict.iteritems())
Any hashable value is a valid Python Dictionary Key. For this reason, None is a perfectly valid candidate. There’s no confusion when looking for non-existent keys – the presence of None as a key would not affect the ability to check for whether another key was present. Ex: >>> d = {1: ‘a’, 2: ‘b’, … Read more
You need to call the hasOwnProperty function to check whether the property is actually defined on the object itself (as opposed to its prototype), like this: for (var key in widthRange) { if (key === ‘length’ || !widthRange.hasOwnProperty(key)) continue; var value = widthRange[key]; } Note that you need a separate check for length. However, you … Read more
To iterate over all the key-value pairs in a table you can use pairs: for k, v in pairs(arr) do print(k, v[1], v[2], v[3]) end outputs: pears 2 p green apples 0 a red oranges 1 o orange Edit: Note that Lua doesn’t guarantee any iteration order for the associative part of the table. If … Read more
You don’t. Your array doesn’t have a key [1]. You could: Make a new array, which contains the keys: $newArray = array_keys($array); echo $newArray[0]; But the value “one” is at $newArray[0], not [1]. A shortcut would be: echo current(array_keys($array)); Get the first key of the array: reset($array); echo key($array); Get the key corresponding to the … Read more
int and const int are two distinct types. std::map<int, float> and std::map<const int, float> are, similarly, different types. The difference between std::map<const int, float> and std::map<int, float> is, to a degree, analogous to the difference between, say, std::map<int, float> and std::map<std::string, float>; you get a fresh map type for each. In the non-const case, the … Read more
Try this editText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if(actionId==EditorInfo.IME_ACTION_DONE){ //do something } return false; } });
Mongo 2.0 added an $and operator, so you can do a query like this: db.things.find({$and: [{$or : [{‘a’:1},{‘b’:2}]},{$or : [{‘a’:2},{‘b’:3}]}] }) http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24and
It is possible to do, but either using Ctrl + Shift + P -> “Emmet: Go to Matching Pair” or by manually setting a shortcut for it (Ctrl + K Ctrl + S). Unfortunately there is currently no support for it out of the box.