In Main  Student st=new Student(1,"snack"); Student st1=new Student(2,"jack"); Student st2=new Student(2,"jack"); Set&lt;Student&gt; hs=new HashSet&lt;Student&gt;(); hs.add(st); hs.add(st1); hs.add(st2);     System.out.println(hs);   O/P:[1 snack, 2 jack, 2 jack]  In Student  @Override public int hashCode() {     // TODO Auto-generated method stub     return this.id; }  @Override public boolean equals(Student obj) {      if(this.id==obj.id)         return false;     else         return true;   My objective is not to allow student who has the same id..name can be the same. Please provide details how HashSet checks which element is a duplicate? All I know that HashSet returns true or false based on hashcode() and equals() method. What works in back end?
What issues / pitfalls must be considered when overriding equals and hashCode?
PrintWriter and PrintStream never throw IOExceptions Some days ago I realized that  (as well as ) never throw an IOException when writing, flushing or closing.  Instead it sets an internal flag (trouble=true) when an error occurs. It's not possible to get the exact exception, but only if there was some exception ().  My question is: why would one want to have such behavior? Isn't that bad API design? On  we try really hard to fix spelling, grammar, and capitalization mistakes in question titles in order to avoid the . But occasionally someone enters a question with an all-lowercase title ().  It would be useful if the system could nudge the user toward capitalizing titles property by showing a hint when the user appears to be capitalizing incorrectly. For instance:    As  and  note in comments, the feature should also try to detect and advise against Title Case and ALL CAPS. How could a gap between array modifier created objects be closed? How do I get a block with data to place myself? Are you looking for how to use /setblock with blocks with data? See .  How do I get a block with data in my inventory so I can place it myself? In Java Edition, these commands work: give @s chest{BlockEntityTag:{Items:[{id:&quot;diamond&quot;,count:10b}]}} give @s sign{BlockEntityTag:{Text1:&quot;{\&quot;text\&quot;:\&quot;foo\&quot;,\&quot;bold\&quot;:true}&quot;}}  How can I do this in Bedrock Edition, where there is no access to NBT tags from commands? Which offences result in indirect free kicks? If a player commits a direct free kick offence in their own penalty area, this results in a penalty kick instead of a direct free kick. However, if the offence is an indirect free kick offence, it remains as an indirect free kick .  What offences result in an indirect free kick? Prove that $T(n) = T(n/3) + T2n/3) + 5n$ is $O(n log n)$ A Google search spewed forth millions of hits on how to find tables without clustered indexed, the PK normally being the clustered index of a table. However, a table could easily have a natural key as a clustered index, and a non-clustered surrogate index, like an identity column.  How do I find all tables in a DB without a primary key defined? I have 245 tables in this DB: manual inspection is grossly inefficient. Prevent Photos app on OSX from launching when plugging in device The Photos app opens whenever I plug in my phone.    How can this be prevented?  I have seen many solutions for the old iPhoto app that involve changing the "Connecting camera opens" option, but the new app has no such option. Why do prisms work (why is refraction frequency dependent)? It is well known that a  can "split light" by separating different frequencies of light:    Many sources state that the reason this happens is that the  is different for different frequencies.  This is known as .  My question is about why dispersion exists.  Is frequency dependence for refraction a property fundamental to all waves?  Is the effect the result of some sort of non-linearity in response by the refracting material to electromagnetic fields?  Are there (theoretically) any materials that have an essentially constant, non-unity index of refraction (at least for the visible spectrum)? Many To Many Relationships 'sudo su -' vs 'sudo -i' vs 'sudo /bin/bash' - when does it matter which is used, or does it matter at all? small limits in the pointed category of a category with all small limits In Hovey, Model Categories, he says that given a category $\mathcal{C}$ with a small limits and colimits, if we form the category of pointed objects ,i.e. the category with objects as morphisms $*\rightarrow A$ where * is the terminal object, then this category $\mathcal{C}_*$also has all small limits and colimits.  To prove this, for any Functor $F:J\rightarrow \mathcal{C}_* $ where $J$ is small we compose it with the forgetful functor $\mathcal{C}_* \rightarrow \mathcal{C}$ and take the limit here. My question is how will this give a limit in $\mathcal{C}_*$? we will get an object in the category, but how do we get the arrow from $*$ to that object? CSV text files loading error / crash in QGIS 2.18.8 I got a problem when I try to load tab-separated text files in the "Create a layer from the delimited text file" tab (that one with de comma symbol). After normally selecting the X and Y fields and clicking OK, the reference coordinate system (SRC) selector screen appears, then the program closes by itself. I had uploaded more than a hundred of this type of file by the same procedure in the previous version of QGIS (2.14 Essen) and have no problem, but since I updated to version 2.18.8 (Las Palmas) I can not load any files or .CSV type.   Do anyone knows what's happening? Am I doing anything wrong? For example:  me$ FOO="BAR * BAR" me$ echo $FOO BAR file1 file2 file3 file4 BAR   and using the \ escape character:  me$ FOO="BAR \* BAR" me$ echo $FOO BAR \* BAR   I'm obviously doing something stupid.  How do I get the output BAR * BAR? As a disclaimer, I must admit this may benefit me (I haven't checked), but probably not as significantly as most others. This issue is also something that has prevented me from answering questions by users with 1 rep in the past, especially if they are poorly fashioned. The Problem New users with a programming question find SO from various methods, such as google. They ask a question with haste, hoping for a quick answer -- which they usually receive. Many of these users have no interest in Stack Overflow itself, but are simply interested in getting the solution they require. As a result of this, they'll check the site regularly for the first day or two until a sufficient answer has been posted. Once they get what they need, they bail; without the required rep or understanding that they should up-vote and select a response as the answer. The Result A great many questions on SO are abandoned by users with no intention of ever coming back. The answer they require has been provided, but for one or more reasons they have neglected their duty of contributing back by way of awarding reputation. The Reach (Since Jeff loves Datum) Some queries on the data dump examine the reach of this 'problem'. The query I used is based on extensions of the following base query; SELECT p1.Id, p1.Score, p1.OwnerUserId, p2.OwnerUserId, p2.Score FROM posts p1  INNER JOIN posts p2 ON (p1.Id=p2.ParentId) LEFT JOIN users ON (p1.OwnerUserId=users.Id) WHERE p2.Score &gt;= 2  AND p2.Score = ( SELECT MAX(p3.Score) FROM posts p3 WHERE p3.ParentId=p1.Id ) AND users.Reputation &lt; 15 AND p1.PostTypeId = 1 AND p1.AcceptedAnswerId = 0  Result: 3,288 Questions by users with under 15 rep which have answers with 2+ up votes that have no accepted answer. Adding: AND (users.LastAccessDate-p1.LastActivityDate) &lt; 604800 // 1 week AND p1.CreationDate &lt; 1249084800 // 1249084800 is 1 week before latest dump data  to the where clause further reveals that 877 questions that have answers with 2+ up votes have no accepted answer, and the owner of the question has not returned since the week the question was asked. Modifying there where clause, and removing the left join: AND p1.OwnerUserId = 0    Reveals a staggering 3,675 questions with answers of 2+ votes by deleted users.  These are questions that were probably answered but the users who did the work can never be recognized. Building off the previous and using an even more restrictive WHERE clause WHERE p2.Score &gt;=5  Still 1,178 posts that can never have an accepted answer. How many posts are there with over 5 up votes that don't provide the correct answer? Modifying the where clause for Reputation to AND users.Reputation = 1  Still reveals 388 questions by users with 1 rep have been abandoned. Solution Similar to how bounty questions work, if a user has abandons the site (not active since x time after the question was asked) with a question that has answers with 2+ up votes, force the answer with the most up votes to be the selected answer. This will reduce the amount of questions that are unanswered, and also give users more of an incentive to answer questions by new users without extra hesitation.  Update Added more statistics for deleted users.  Please feel free to add/remove rules to make this a truly practical feature. I have a dataset in csv file format that I'm loading into pgfplotstable. I can't change the format of the original csv, and being financial data it has a column of item names and two or three explanatory data points at the top of the table. e.g.  \documentclass{article} \usepackage{array,datatool,pgfplotstable}   \begin{filecontents}{sample.csv}     item,2008,2009,2010,2011      ,Actual,Actual,Forecast,Forecast      ,GBP,GBP,GBP,GBP      ,('000),('000),('000),('000) rounded     Area 1 OP, 1000000,1500000,1750000,250000     Area 2 OP, 400000,500000, 450000,-50000     Area 51 OP, 300000,375000,390000,15000     No P, 1250000, 1000000, 950000, 50000     Residuals, 800000, 80000, 90000, 10000   \end{filecontents}  \pgfplotstableread[col sep=comma]{sample.csv}\mystuff   I'm stumped at the next stage which is to typeset \mystuff so I have comma separators and can add a row that sums the 'Area' columns. At the moment to display the table I have to do something like  \begin{document}  \pgfplotstableread[col sep=comma,header=false]{sample.csv}\mystuff  \pgfplotstabletypeset[   columns/0/.style={string type},   columns/1/.style={string type},   columns/2/.style={string type},   columns/3/.style={string type},   columns/4/.style={string type}]\mystuff  \end{document}   How do I tag the top three rows as string and the rest of the last four columns as integer type so I can format and transform them? Better to buy an older high-level camera or newer entry-level camera? What are the pros and cons of buying an older higher-level camera if the price is about the same as a new entry-level one? When running 'screen ls' the screen stops with the text [screen is terminating]. I would like screen to keep the session alive and reattach to it to see the output of ls.  Of course the real thing is that I don't run screen ls, but rather a screen fsck ..., so I would like to ensure that the screen is not terminating when this command is finished.  I would love to have an answer that is useful for an already existing running screen session, so some interactive keys like C-a ... or C-a : (Enter command line mode) Number of labeled trees which have one vertex of degree 4 How many labeled trees which have one vertex of degree 4 can we have? A tree with $10$ vertices has $9$ edges, so the sum of the degrees of the vertices is $2\cdot 9=18$. If there is one vertex of degree $4$, the sum of the degrees of the other $9$ vertices must be $14$. I don't know what to do next. Should I count all possible vertex degrees? Is there a way I can inspect my character's face at any point in the game after creating it during the bathroom scene?  I am playing on PlayStation 4 and rotating with the right stick in 3rd-person view obviously does not show the face. I haven't found any mirrors or shiny objects to use the reflection either.  The reason for this is that I forgot what she looks like and also I want to share my monstrous creation with others but I have already left the vault!