Forgive me if  it seems simple but I couldn't figure it out easily. I thought about using a loop but was wondering if anybody knows an easier way: I have:  Map&lt;String, Integer&gt; map = new HashMap&lt;&gt;();          map.put("ClubB", 1);         map.put("ClubA", 2);         map.put("ClubC", 2);         map.put("ClubD", 2);         map.put("ClubE", 3);         map.put("ClubF", 2);         map.put("ClubG", 2);   I need to get keys or values at specific index in my tests. For example I need to get the key and value at index 3 etc. The reason is that I use a comparator and sort the Map and would like to show that the value at a specific index has changed.  Thanks for any ideas.  UPDATE:  I used:  HashMap leagueTable = new HashMap(); Map&lt;String, Integer&gt; map = sortByValues(leagueTable);   public &lt;K extends Comparable&lt;K&gt;, V extends Comparable&lt;V&gt;&gt; Map&lt;K, V&gt; sortByValues(final Map&lt;K, V&gt; map) {         Comparator&lt;K&gt; valueComparator = new Comparator&lt;K&gt;() {             public int compare(K k1, K k2) {                 int compare = map.get(k2).compareTo(map.get(k1));                 if (compare == 0) {                     return k1.compareTo(k2); // &lt;- To sort alphabetically                 } else {                     return compare;                 }             }         };         Map&lt;K, V&gt; sortedByValues = new TreeMap&lt;K, V&gt;(valueComparator);         sortedByValues.putAll(map);         return sortedByValues;     }   I then used aloop to print out values:  for (Map.Entry&lt;String, Integer&gt; entry : map.entrySet()) {                      System.out.println( entry.getKey() + ", " + entry.getValue() ); }
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?
Should we pass a shared_ptr by reference or by value? Discovering new features On a series involving harmonic numbers Recommended way to initialize srand? I need a 'good' way to initialize the pseudo-random number generator in C++. I've found  that states:     In order to generate random-like   numbers, srand is usually initialized   to some distinctive value, like those   related with the execution time. For   example, the value returned by the   function time (declared in header   ctime) is different each second, which   is distinctive enough for most   randoming needs.   Unixtime isn't distinctive enough for my application. What's a better way to initialize this? Bonus points if it's portable, but the code will primarily be running on Linux hosts.  I was thinking of doing some pid/unixtime math to get an int, or possibly reading data from /dev/urandom.  Thanks!  EDIT  Yes, I am actually starting my application multiple times a second and I've run into collisions. A question that may sound very trivial, apologies beforehand. I am wondering why $( \mathbb{Q}_{&gt;0} , \times )$ is not isomorphic to $( \mathbb{Q} , + )$. I can see for the case when $( \mathbb{Q} , \times )$, not required to be positive, one can argue the group contains elements with order 2 (namely all negatives). In the case of the requirement for all rationals to be positive this argument does not fly. What trivial fact am I missing here? SSH login without password with kerberos What does the function f: x ↦ y mean? I am doing , and am having a few problems with function notation. I understand the form f(x).  What does the form f: x ↦ y mean? Could you also give one or two examples?  And, if possible, state your source. Thank you. How to clear the interpreter console? 74190 counter problem So, I got my 74190 counter shows number like this  9-8-7-6-5-4-3-2-1-0-5-4-3-2-1-0-5-4-3-2-1-0-5-4-3-2-1-0 and so on.  My questions:   What can I do to change the output count down into 5-4-3-2-1-0-5-4-3-2-1-0 and so on? When it changes 0 into 5 it moves so fast. How could I fix this one? I just read  on EE.SE and that triggered a doubt in me.  If I were asked whether there is any relationship between the electrical resistivity and the density of a substance I'd answer negatively, but is it really so?   Is there really no (relevant) relationship between those two bulk properties of a material? Can anyone confirm or disprove this and give some explanation thereof? Explaining two-tailed tests I am looking for various ways of explaining to my students (in an elementary statistics course) what is a two tailed test, and how its P value is calculated.  How do you explain to your students the two- vs one- tailed test? Run Trigger As A Specific User (or Profile)? Is this possible?  I'm not finding help, Google or otherwise, for this.  Situation:  A trigger runs and cycles through groups of Opportunities.  Some of these Opportunities are Closed Won, and most users of the system are not allowed to Edit Closed Wons (especially the Sales team).  But I need this trigger to be able to touch the Opps (it's fired when the User touches the Account and subsequently a group of Opps under that account gets touched).  It is a VALIDATION RULE blocking them.  Ultimately, I may investigate, if no other option, setting a HIDDEN FIELD on the Opp before updating, then clearing if after, and putting bypass code in the Validation rule.  This is a backup plan.  I'd like to know how to "Run As" a specific profile though.  Anyone have an example of this?  I have three profiles out of twelve that can touch Closed Wons... Is there a difference here:        It happened that he did not go to work today.   As it happened, he did not go to work today.      Do "it happened that" and "as it happened" have different meanings? After trying to delete apache and tomcat, and now trying to reinstall apache 2, I am missing the init.d/apache2 file to start/stop my server.  I am not sure if the new install actualy worked, and my apt-get purge apache2 didn't remove everything in the first place!  How can I get the init.d/apache2 file to test if server starts / is installed properly (I had removed files and directories manually)? how to suppress "chapter" in \chapter (while keeping numbering) How do I install a .deb file via the command line? Should we have a tag for significant points in time? There are many discussions about the current incidence. For example:          Should we have a whole tag for this incidence? In general, if in the future there are more crises and incidences like this, should they have their own tags too? I feel it's fine, as we have specific tags for individual events like . And, should we have a  tag?    Related:        Note that these questions are specifically about the conflict 2019, while this question is simply about creating meta tags for significant events. How to prove a cross is not locally homeomorphic to an euclidean space? Consider the subset $X = \{(x, 0) \mid -1 \lt x \lt 1\} \cup \{(0, y) \mid -1 \lt y \lt 1\} \subset \Bbb R^2$. It's just two open segments intersecting at $(0, 0)$.  How do you show that $X$, equipped with the subspace topology of $(\Bbb R^2, \lvert \lvert \cdot \rvert \rvert_2)$, is not locally homeomorphic to an euclidean space because of the point $(0, 0)$ ? What is the typographic reasoning here? Does it make the text look less crowded? On duplicate questions, I often see different headings for the duplicate question list. These include:     Possible Duplicate:    [duplicate question list]   and      This question already has an answer here:    [duplicate question list]   and more recently,     This question is an exact duplicate of:    [duplicate question list]   What decides which heading is placed before the duplicate question list?