I have a HashMap as follows:  public class MyHashMapOfEmployees {    public static void main(String a[]){     Map&lt;String,Employee&gt; allEmployees= new HashMap&lt;String,Employee&gt;();     allEmployees.put(new Employee("111",("Ram", "Smith", "developer"));     allEmployees.put(new Employee("222",("John", "Doe", "manager"));     allEmployees.put(new Employee("333",("Lisa", "Hart", "CEO"));     allEmployees.put(new Employee("444",("Mark", "Wayman", "VP"));   } }   Here is my Employee class:  class Employee{      private String firstName; private String lastName; private String position; private String id;  public Employee(String fn, String ln, String p){     this.firstName = fn;     this.lastName = ln;     this.position = p; }      public String getFirstName() {     return firstName; } public String getLastName() {     return lastName; } public String getPosition() {     return position; } public String getId() {     return id; }   }  I need to sort my HashMap by employees first name, and keys (id) can be omitted. Final output should be as follows:  John Doe manager Lisa Hart CEO Mark Wayman VP Ram Smith developer   I tried using the following comparator:  private final Comparator&lt;Employee&gt; employeeComparator = new Comparator&lt;Employee&gt;() {     @Override     public int compare(Employee o1, Employee o2) {         return o1.getFirstName().compareTo(o2.getFirstName());     } };   How can I sort this HashMap not by the value (which in my case is an object - Employee), but by a particular field in my object (firstName)?  Is TreeMap not the right solution?  I've searched through stackOverflow and there is nothing for this particular scenario that I could apply and get to work. THIS ISN'T A DUPLICATE, the link that is being offered in comments is a different task.  Can I do the following without creating a TreeMap in between?  SortedSet&lt;Map.Entry&lt;String, Employee&gt;&gt; employeesSortedByFirstName = new TreeSet&lt;Map.Entry&lt;String, Employee&gt;&gt;(employeeComparator());   employeesSortedByFirstName.addAll(allEmployees.entrySet());   Would this sort my map values by first name?... or by the order of insertion?..  OR - do I need a TreeMap in between as such:  SortedSet&lt;Map.Entry&lt;String, Employee&gt;&gt; employeesSortedByFirstName = new TreeSet&lt;Map.Entry&lt;String, Employee&gt;&gt;(employeeComparator());  SortedMap&lt;String, Employee&gt; sortedMap = new TreeMap&lt;String, Employee&gt;(); sortedMap.putAll(allEmployees); //hashmap into treemap employeesSortedByFirstName.addAll(sortedMap.entrySet()); //add treemap into the sorted set   THE GOAL IS TO SORT BY FIRST NAME, NOT BY THE WHOLE VALUE OF THE MAP.
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?
When I installed my SSD I just mounted with discard and didn't sweat it. However today I was reading about the pros and cons of using fstrim instead and decided to run the program to get an idea of how long it would actually take (still with my partitions mounted with discard). The command took several minutes on both my root and home partitions. For my home partition I used -v and got this:  $ sudo fstrim -v /home /home: 137494052864 bytes were trimmed   This is more than the amount of free space on the partition!  $ df -h /home Filesystem      Size  Used Avail Use% Mounted on /dev/sda2       206G   78G  118G  40% /home   Subsequent runs finish in less than a second, eg:  $ sudo fstrim -v /home /home: 0 bytes were trimmed   Surely if I have always had the partition mounted with discard, fstrim should not trim a large amount of data like that? The discard option is definitely enabled, here are the relevant fstab lines:  UUID=xxxxxxxx...    /          ext4   noatime,discard,errors=remount-ro  0      1 UUID=xxxxxxxx...    /home      ext4   noatime,discard,errors=remount-ro  0      2   And mount output lines:  /dev/disk/by-uuid/xxxxxxxx... on / type ext4 (rw,noatime,discard,errors=remount-ro,stripe=128,data=ordered) /dev/sda2 on /home type ext4 (rw,noatime,discard,errors=remount-ro,stripe=128,data=ordered)   The SSD is a TOSHIBA THNSNS256GMCP. Why does this happen? Is it Safe to Delete Files From /var/tmp? How can I search in another language? Let's say I have Windows installed on drive C, however I install all of my programs on the D drive, and I keep my user profile on the D drive as well (things like My Documents). How can I have Windows use those folders instead of the ones on the C drive? Android 5.0 (Lollipop) was officially announced on October 15th, 2014.  You can review the high-level changes at the  and the announcement on the official .  Of course, not all devices will get this update right away and others won't get it at all. Each manufacturer and carrier often choose to add their custom modifications which tend to delay the official release.  When will each device get Android 5.0, either officially or unofficially, if ever?  See also: Do the 46 human chromosomes form a single unbroken DNA helix?  Or is it rather that a human's genome consists of 46 disconnected helices?    If it is the former, does the common numbering scheme for the chromosomes have any correlation to their actual ordering in the one large strand?  If is the latter, is there a convention on how the chromosomes are ordered in genomic datasets?  Also, is there a clear understanding of how sister chromosomes "find" each other in Meiosis I?  Generally, during periods when Mitosis/Meiosis are not occurring,  what's a good physical picture for how the chromosomes are physically arranged (e.g. a bowl of 46 spaghetti noodles, or maybe the sister chromosomes always stay close together, etc)  thanks! Is there an intelligent way to left-align the parts right of &amp; of the two cases environments shown below (if x >= 0, otherwise, if y &lt; 0, otherwise). I wonder if there is a better way than using manual spaces:  \begin{align*}  u(x) &amp;=   \begin{cases}    0        &amp; \text{if } x \geq 0 \\    1        &amp; \text{otherwise}   \end{cases}   \\  \tau &amp;=   \begin{cases}    a+b+c+d  &amp; \text{if } y &lt; 0 \\    1        &amp; \text{otherwise}   \end{cases} \end{align*} How prove that $q \geq b+d$ for $ad-bc = 1$ and $\frac{a}{b} > \frac{p}{q} > \frac{c}{d}$? Let $a,b,c,d,p$, and $q$ be natural numbers such that $ad-bc = 1$ and $\frac{a}{b} &gt; \frac{p}{q} &gt; \frac{c}{d}$.  How prove that  $q \geq b+d$? Experience using dropdowns in-line of sentence "mad lib" style Do you have experience implementing text inputs or drop-downs in-line with other text or forms? Is this approach any better than just creating a separate field/label?  In the example below the user has the option to indicate when to be reminded again (in one, two, or three days). When they are reminded of an assignment, they simply get an email or text message. Change equation font in Pages During a Pages update which was pushed out a few months ago, Pages obtained the ability to write equations using LaTeX or MathML commands. According to an Apple Support article, the size and color of the equation can be changed ():  The equation appears at the insertion point in your document (or before the selected text). The equation is an inline object, the same size and color as the surrounding text. If you change the size or color of the surrounding text, the size and color of the equation’s font also change.  This does not mention anything about the font used for the equation itself, which seems to be something similar to a Times New Roman font. Is there any way to change the font used, preferably to something like Latin Modern Math? I was considering the possibility of replacing the font file Pages uses with a downloaded Latin Modern Math font file, but I'm not sure what to replace. Could I replace Times New Roman in /System/Library/Fonts/ or something like that? Why don't we have an isomorphism between $R[x]$ and $ R[[x]]$? Fiction novel or movie about sentient dinosaurs Profile avatar lost on several sites after profile edit (Gravatar replaced with Identicon) I have had the same network-wide profile avatar for many years; it's a custom image which I installed nework-wide soon after I registered for Stack Overflow back in 2011. I still see that image e.g. on  and  but not, for instance, on this site, or e.g. on   (The example originally linked to my Unix &amp; Linux profile instead of Super User but I experimentally changed my profile back to the gravatar one there.)  I routinely update my profile presentation text every few months, and did so again a few days ago. Comments below seem to indicate that others who recently edited their profile are experiencing the same problem.  My preferred avatar is a Gravatar which is connected to my email address, which has always been the same (MD5 091f411d57db5be8298e057a32e5ad72). The replacement seems to be a generic identicon with a different MD5. I don't recall seeing this identicon as an option in my profile before:    You'll notice that the gravatar is still visible as an option, but I can find no way to replace it on all sites in one go. I switched back to the gravatar one on Unix &amp; Linux and noticed that the help next to the "Save" button says     Your profile will be updated on all public communities.   but alas, that did not in fact happen. Do I really have to go over 170+ member sites and manually select my gravatar on each? Why doesn't the definition of a category require an explicit notion of morphisms equality? I am learning basics of the category theory (CT).  I do understand that CT is a modern powerful framework to describe various branches of mathematics in a unified way.  I do admit that category's definition tells a lot about the whole thing and focuses on the most important properties, shadowing unnecessary details. However, the more I go forward, the more it feels like it should explicitly require a notion of morphisms equality (like it does with morphism composition). It feels so because equality or inequality of morphisms arises everywhere, since the very beginning: any commutative diagram eventually reduces to an equality of two different paths and many other things involve equality as well. Even composition is defined grounding upon an (implicit) equality!  I'll try to give an example of my concern. Consider $\mathbb{SET}$. Its objects are sets and morphisms are functions. Now, let's recall that functions are sets as well - to be more precise, a function $f : A \mapsto B$ is a subset of a $A \times B$ obeying certain properties, which I omit. Thus, one could argue that $f$ is both a morphism between objects $A, B \in Obj(\mathbb{SET})$ and an object defined as a set of pairs $\{ (a_1 \in A, b_1 \in B), ..., (a_n \in A, b_n \in B) \}$ and those are equal because both are essentially exactly the same thing.  I hope my concern is clear and I need some kind of "conceptual insight" from knowledgeable people to move forward. Please give me the right perspective. How could I write a command in LaTeX, so after compiling it will be shown as a text in PDF and not executed?  For Example, I would write \it This is how you write in italic and the compiled pdf would contain the exact same text between the quotation marks without \it being executed. What is an observer in quantum mechanics? Web applications that want to force a resource to be downloaded rather than directly rendered in a Web browser issue a Content-Disposition header in the HTTP response of the form:  Content-Disposition: attachment; filename=FILENAME  The filename parameter can be used to suggest a name for the file into which the resource is downloaded by the browser.  (Content-Disposition), however, states in  (The Filename Parameter) that the file name can only use US-ASCII characters:     Current [RFC 2045] grammar restricts   parameter values (and hence   Content-Disposition filenames) to   US-ASCII.  We recognize the great   desirability of allowing arbitrary   character sets in filenames, but it is   beyond the scope of this document to   define the necessary mechanisms.   There is empirical evidence, nevertheless, that most popular Web browsers today seem to permit non-US-ASCII characters yet (for the lack of a standard) disagree on the encoding scheme and character set specification of the file name. Question is then, what are the various schemes and encodings employed by the popular browsers if the file name “naïvefile” (without quotes and where the third letter is U+00EF) needed to be encoded into the Content-Disposition header?  For the purpose of this question, popular browsers being:   Firefox  Internet Explorer  Safari Google Chrome  Opera Question I use pgfplots with the ultra thick option ans without explicitly giving the domain for the y-axis. It seems that in this case, some part of my graph is &quot;eaten&quot; by the margin: see the picture below to understand what I mean. Is there a way to avoid this? Code \documentclass{article} \usepackage{pgfplots} \begin{document}  \begin{tikzpicture}  \pgfplotsset{every axis/.append style={                     axis x line=middle,    % put the x axis in the middle                     axis y line=middle,    % put the y axis in the middle                     axis line style={-&gt;},  % arrows on the axis                     xlabel={$x$},          % default put x on x-axis                     ylabel={$y$},          % default put y on y-axis                     grid = major                     }}  \begin{axis}[xmin=-5,xmax=5] \addplot[orange,smooth, ultra thick] {sin(deg(x))} ;                  \end{axis} \end{tikzpicture}  \end{document} Why can't I connect to Ubuntu One? I have purchase new laptop from Dell with ubuntu 12.04 preinstalled. while connecting to Ubuntu One following occurs and I am not able to sync with Ubuntu One.   WebClientErr u'Error downloading https://one.ubuntu.com/api/account/ - server replied:Not       Found' u'&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;\n&lt;html&gt; &lt;head&gt;\n&lt;title&gt;404 Not Found&lt;/title&gt;\n&lt;/head&gt;&lt;body&gt;\n&lt;h1&gt; Not Found&lt;/h1&gt;\n&lt;p&gt;The requested URL /api/account/ was not found on this server. &lt;/p&gt;\n&lt;hr&gt;\n&lt;address&gt;Apache/2.2.22 (Ubuntu) Server at one.ubuntu.com Port 443 &lt;/address&gt;\n&lt;/body&gt;&lt;/html&gt;\n' In C++, what is a virtual base class? I want to know what a "virtual base class" is and what it means.  Let me show an example:  class Foo { public:     void DoSomething() { /* ... */ } };  class Bar : public virtual Foo { public:     void DoSpecific() { /* ... */ } };