{"5eaa9ce8": {             "Id": "1958208",             "priority": 0              }, "5eaa9bs8": {             "Id": "1958208",             "priority": 2              }, "6eaa9ce8": {             "Id": "1958208",             "priority": 1              } }   Need to sort this Map based on the priority of the key.  and needed output is { "5eaa9bs8": {                 "Id": "1958208",                 "priority": 2                  }, "6eaa9ce8": {                 "Id": "1958208",                 "priority": 1                  }, "5eaa9ce8": {                 "Id": "1958208",                 "priority": 0                  } }
1054
I am relatively new to Java, and often find that I need to sort a Map&lt;Key, Value&gt; on the values.  Since the values are not unique, I find myself converting the keySet into an array, and sorting that array through array sort with a custom comparator that sorts on the value associated with the key.  Is there an easier way?
89253
Take a look at the  and the Priority column.  If sorted in descending order you get critical, major, normal, and minor issues, in that order.  Since "normal" would not go between "major" and "minor" in alphabetical order, they've obviously defined a custom sequence to use for sorting.  How is this done in Drupal?  Is it merely sorting based on a numeric value that is not displayed?  Or is it more clever than that?
90953
A weak key for DES is a key $K$ such that $DES_{k_1}(DES_{k_2}(x))=x$ for all $x$.  I don't get why are the 4 keys $k_1||k_2$: $1^{112}$, $0^{112}$, $0^{56}||1^{56}$, $1^{56}||0^{56}$ considered as weak. (Also didn't find some detailed explanation in the web.)
2532
I have a dictionary: keys are strings, values are integers.  Example:   stats = {'a':1000, 'b':3000, 'c': 100}   I'd like to get 'b' as an answer, since it's the key with a higher value.  I did the following, using an intermediate list with reversed key-value tuples:  inverse = [(value, key) for key, value in stats.items()] print max(inverse)[1]   Is that one the better (or even more elegant) approach?
80273
If I have a dictionary like:  { 'a': 1, 'b': 2, 'c': 3 }   How can I convert it to this?  [ ('a', 1), ('b', 2), ('c', 3) ]   And how can I convert it to this?  [ (1, 'a'), (2, 'b'), (3, 'c') ]
78889
Is there a way to change all the numeric keys to &quot;Name&quot; without looping through the array (so a php function)? [     0 =&gt; 'blabla',     1 =&gt; 'blabla',     2 =&gt; 'blblll',     // etc ... ]
107220
I have a map. the string is the label of a field of an object and the integer is the value that must go into this field of that object. But i don't know how to retrieve the API name of those fields from their labels. Please help!  Thanks in advance!
52728
Multimap essentially has groups of data sorted by the key. I want a method by which I could access these individual groups and get their aggregate values. For example, in a std::multimap&lt; string, int &gt; I store   {"Group1", 1},  {"Group1", 2},  {"Group1", 3},   {"Group2", 10},  {"Group2", 11},  {"Group2", 12}   Having stored these values, I should be able to iterate this multimap and get the aggregate values of each "group". Problem is there aren't any functions defined in STL to access MultiMaps in such a way. I could use lower_bound, upper_bound to manually iterate the multimap and total the group's contents, but I am hoping there could be better ways already defined in STL ? Can anyone propose a solution as to how I could get the aggregate values for a group in the above example.
45508
I am aware that it is possible to sort primarily by one field and secondarily by another field. For example:   $ echo -e "1 5\n1 4\n8 2\n1 9" | sort -k 1,1n -k 2,2n 1 4 1 5 1 9 8 2 $    However, am I correct that sort always keeps the lines intact, e.g. it is not possible to sort in a way that output would be following:  1 2 1 4 1 5 8 9   If this is not possible with sort, then what would be the correct tool for this?
118273
I'm trying to parse json response.. but keep getting this error      Invalid conversion from runtime type List ANY> to Map String,ANY>   Map&lt;String, Object&gt; MapLv3 = new Map&lt;String, Object&gt;();      Integer x2 = 0; for (Object oh : CallsList){     MapLv3.put(String.valueof(x2), oh);     x2++; } index = x2; System.debug('Map Lv 3 ==&gt;'+MapLv3);  Map&lt;String, Map &lt;String, Object&gt;&gt; Map3 = new Map&lt;String, Map &lt;String, Object&gt;&gt;(); for (Integer a2 = 0; a2 &lt; index; a2++){     Map3.put(String.valueof(a2),(Map&lt;String,Object&gt;) MapLv3.get(String.valueof(a2))); } System.debug('Segment ==&gt;'+Map3.get('0').get('segments'));
46281
In Dan Appleman's book Advanced Apex Programming, he explains how using SObjects as Map keys (i.e. Map&lt;SObject, *value*&gt;) is supported but it's poor practice, since the key is actually determined by a hash of all the fields on that SObject key - so if there's a change to even just one field, the key is changed.   My question is - why is this supported? I'm having trouble thinking of even one case where using this type of collection would be desired? The point of using a Map is to be able to retrieve data based on semantic-trivial, immutable data (such as IDs)...
63309
I just saw this behaviour and I'm a bit surprised by it...  If I add 3 or 4 elements to a Dictionary, and then do a "For Each" to get all the keys, they appear in the same order I added them.  The reason this surprises me is that a Dictionary is supposed to be a HashTable internally, so I expected things to come out in ANY order (ordered by the hash of the key, right?)  What am I missing here? Is this a behaviour I can count on?  EDIT: OK, I thought already of many of the reasons why this might happen (like the separate list to entries, whether this is a coincidence, etc). My question is, does anyone know how this really works?
4615
Given a dictionary like so:  my_map = {'a': 1, 'b': 2}   How can one invert this map to get:  inv_map = {1: 'a', 2: 'b'}
44281
I often have to sort a dictionary, consisting of keys &amp; values, by value. For example, I have a hash of words and respective frequencies, that I want to order by frequency.  There is a SortedList which is good for a single value (say frequency), that I want to map it back to the word.   orders by key, not value. Some resort to a , but is there a cleaner way?
112859
Is there a better way to do this?  string[] s = {"zero", "one", "two", "three", "four", "five"};  var x =  s .Select((a,i) =&gt; new {Value = a, Index = i}) .Where(b =&gt; b.Value.StartsWith("t")) .Select(c =&gt; c.Index);   i.e. I'm looking for a more efficient or more elegant way to get the positions of the items matching the criteria.
827
If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it,  what is the most efficient way of going through the map?  Will the ordering of elements depend on the specific map implementation that I have for the interface?
66606
I'm working on a batch which getting a params from another batch in the finish method.  The Params are :    A Map - Map&lt;Sobject,Set&lt;String&gt;&gt; A Set -  Set&lt;String&gt;   I lost the values of my Map on the second run of the execution method - Means - Map.get(Sobject) returned with null although it had values in it.  That happened only within the second to the last run of the batch (from the second till the end of the chunks).  The first chunk getting the values as expected.  I guess it could be because defined a Sobject as a Key in a Map is not Best Practice because Hashing issue - Because the second param that I'm sending to the batch is a Set&lt;String&gt; - And it keeps its values for all the chunks.   Because of this issue, I decided to send a Set&lt;Id&gt; of all the Sobjects from the first batch, and retrieve the records in the second batch with SOQL query. and I wanted to know what are the best practices to do so.  the queryLocatoer in the Start method is needed to go over another Sobject without any related to the Sobject that I sent.  Where can I put this Query? Can I put it inside the Constructor and assign it to a global variable? Inside the Start method before I set the query for the queryLocator? - since it always will be the same results, I don't want to put it on the execute method.  What do you think? Why we have hashing issue when the key of a Map is a Sobject?  Thanks!