Java if statement in nested loop not matching , counting first occurrence I have been having an issue which I feel should be simple to do but I cannot understand why it is not returning the expected results.  I have an array of Strings called User and a List of objects called Sales. Within Sales there is an field called User. What I wish to do is for each User in the array, I wish to match the sales object.  String[] User = {"John","Bob","Pete"};     //The sales object looks like      {    User: Bob    Dep: Hardware     }     {    User: Bob    Dep: Software     } ...  //The nested loop looks like    for (int i = 0; i &lt; User.length; i++)         {            for (int j = 0; j &lt; Sales.size(); j++ )         {                 if (User[i] == Sales.get(j).getUser())                 {                        System.out.println(Sales.get(j).getUser() +  Sales.get(j).getDep()                }             }   What I am expecting to printed is:  Bob Hardware  Bob Software  However all I am seeing is   Bob Hardware  Can anyone see what is wrong with my logic/approach?
How do I compare strings in Java? I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug.  Is == bad? When should it and should it not be used? What's the difference?
I created a Compute Engine VM (Ubuntu 18.04), and when I log into it using the SSH button in the VM instances list I'm logged in as user username.  After a while, I realised I needed to be able to use another SSH client as well. As per  I enabled OS Login by adding a key-value pair in metadata, where key is enable-oslogin and value is TRUE.  I then tried to add my existing SSH key:  gcloud compute os-login ssh-keys add --key-file path/to/key.pub --ttl 0  which was successful except one major problem: it has added the key for user username_gmail_com and will only allow me to ssh to my VM as that user:  ssh username_gmail_com@myinstance  And it has also created that user on my VM. From the web interface, I'm logged in to the VM with that new user as well (/home/username_gmail_com). Of course, I can still access the original user's data (/home/username). When I disable OS Login the web interface logs me in as username again and SSH from another client is disabled.   Why is the username different when enabling OS Login? Can I change the username with OS Login enabled?   Edit  There has been an addition to the docs explaining exactly this question. Check here:  and on  all the way at the bottom under "Expected login behaviors". There are infinitely many prime numbers $p$ for which $p + 2$ and $p + 4$ are also prime numbers I need help with this question: There are infinitely many prime numbers $p$ for which $p + 2$ and $p + 4$ are also primes.  Where should I start? what proof techniques will be useful?  Any input will be very useful to me. Establishing a Basis for $F[x]/(f(x))$ Hypothesis:   $f(x) = a_0 + a_1 x + \ldots + a_n x^n \in F[x]$ s.t. $f(x)$ irreducible over field $F$. $deg(f(x)) = n \ge 1$. Let $V = (f(x)) \subset F[x]$.   Goal: Show that $\mathcal{B} = \{1 + V, x + V, x^2 + V, \ldots , x^{n-1} + V\}$ forms a basis for $E = F[x]/V$  Attempt:   Linear Independence: If this set weren't linearly independent, then a non-trivial $b_i \in F$ would satisfy  $$ b_0 + b_1x + \ldots + b_{n-1} x^{n-1} + V = 0 + V $$   But this would then imply that $b_0 + b_1x + \ldots + b_{n-1} x^{n-1}  \in 0 + V$. But this would contradict $V = (f(x))$ since it is impossible that $f(x)\,\,|\,\,b_0 + b_1x + \ldots + b_{n-1} x^{n-1}$ of strictly lower degree.  Now how would I show that this set spans $F[x]/V$? Should I use center or centering for figures and tables? What is the correct way to center figures and tables (figure, table)?  \begin{center} ... \end{center}   or   \begin{centering} ... \end{centering} Is there a terminal command that will log you out of your current desktop session and take you back to the login screen? Pivot rows into multiple columns I have a SQL Server instance that has a linked server to an Oracle server. There is a table on the Oracle server called PersonOptions which contains the following data:  ╔══════════╦══════════╗ ║ PersonID ║ OptionID ║ ╠══════════╬══════════╣ ║        1 ║ A        ║ ║        1 ║ B        ║ ║        2 ║ C        ║ ║        3 ║ B        ║ ║        4 ║ A        ║ ║        4 ║ C        ║ ╚══════════╩══════════╝   I need to pivot that data so the results are:  ╔══════════╦═════════╦══════════╦══════════╗ ║ PersonID ║ OptionA ║ Option B ║ Option C ║ ╠══════════╬═════════╬══════════╬══════════╣ ║        1 ║       1 ║        1 ║          ║ ║        2 ║         ║          ║        1 ║ ║        3 ║         ║        1 ║          ║ ║        4 ║       1 ║          ║        1 ║ ╚══════════╩═════════╩══════════╩══════════╝   Any suggestions? Inherited values between polygons in QGIS In this project, I have three polygons, see the image below  'Polygons_From', includes input attributes, i.g. &quot;Value_1&quot;, &quot;Value_2&quot;, &quot;Value_3&quot;, and $area for each quadrate (on the image there are two types of them). 'Polygons_To' polygons for which new values &quot;Value_1_new&quot;, &quot;Value_2_new&quot;, &quot;Value_3_new&quot; need to be defined 'Border' defines an area where the calculation should be done.   My task is to transfer values from 'Polygons_From' into 'Polygons_To' based on a certain aspect/ratio. Of course, I can simply achieve it with the 'Union' function as was suggested in . It uses $area-factor, but perhaps there are better approaches that will lead me to a much more efficient output? So, I am asking for a recommendation regarding the technique/workflow that can be applied in QGIS 2.18. Shall I consider only $area or there are some other criteria? Moreover, I looking forward to finding some papers that may improve my general understanding of the methodology.  References: Can anyone help me identify a story about kids with silver blood? Player looses boot after tackle Change post permalink to external URL from custom field Mass retagger badge I've been busy retaggin questions since I got my retag privileges.  Shouldn't there be an incentive to retag wrongly tagged questions, other than the urge to do things right?  I'm mean, the only "badge incentive" for retagging are "Firs edit" (Organizer) and "Creation of a tag used 50 times" (Taxonomist). The first one is easy to get, and the second one, right now in SO is almost impossible to get without cheating, that's editing 50 questions with an unlikely tag. Taxonomist I guess, could encourage wrongly tagging.  Is this really a problem?  We could have an "Tagged 200 question" badge, so people go for that badge, instead of taxonomist. Is "aren't I" correct grammar? When should I use # and = in ASP.NET controls? I have been using ASP.NET for years, but I can never remember when using the # and = are appropriate.  For example:  &lt;%= Grid.ClientID %&gt;   or  &lt;%# Eval("FullName")%&gt;   Can someone explain when each should be used so I can keep it straight in my mind? Is # only used in controls that support databinding? We know $$i^2=-1 $$then why does this happen? $$ i^2 = \sqrt{-1}\times\sqrt{-1} $$ $$ =\sqrt{-1\times-1} $$ $$ =\sqrt{1} $$ $$ = 1 $$  EDIT: I see this has been dealt with before but at least with  I'm not making the fundamental mistake of assuming an incorrect definition of $i^2$. Show that some monomial ideal is primary Show that $I=(X_{k_1}^{a_1},...,X_{k_s}^{a_s})$ is $(X_{k_1},...,X_{k_s})$-primary.   I noticed  that $$\sqrt{({X_{i_1}}^{a_1},...,{X_{i_k}}^{a_k})}=\sqrt{({X_{i_1}}^{a_1})+\cdots+({X_{i_k}}^{a_k})}=\sqrt{\sqrt{(X_{i_1})^{a_1}}+\cdots+\sqrt{(X_{i_k})^{a_k}}}=\sqrt{(X_{i_1})+\cdots+(X_{i_k})}=\sqrt{(X_{i_1},...,X_{i_k})}=(X_{i_1},...,X_{i_k}).$$ I have to show that $I$ is $P$-primary (where $P=(X_{k_1},...,X_{k_s})$), i.e., if $u v\in I$ then $u\in I$ or $v\in P$. I tried to prove that if $u\notin I$ and $v\notin P$ then $uv\notin I$. (There is a similar question, but the answer is too hard for me.) Erasing elements from a vector I want to clear a element from a vector using the erase method. But the problem here is that the element is not guaranteed to occur only once in the vector. It may be present multiple times and I need to clear all of them. My code is something like this:  void erase(std::vector&lt;int&gt;&amp; myNumbers_in, int number_in) {     std::vector&lt;int&gt;::iterator iter = myNumbers_in.begin();     std::vector&lt;int&gt;::iterator endIter = myNumbers_in.end();     for(; iter != endIter; ++iter)     {         if(*iter == number_in)         {             myNumbers_in.erase(iter);         }     } }  int main(int argc, char* argv[]) {     std::vector&lt;int&gt; myNmbers;     for(int i = 0; i &lt; 2; ++i)     {         myNmbers.push_back(i);         myNmbers.push_back(i);     }      erase(myNmbers, 1);      return 0; }   This code obviously crashes because I am changing the end of the vector while iterating through it. What is the best way to achieve this? I.e. is there any way to do this without iterating through the vector multiple times or creating one more copy of the vector? Do I have an SSD and a hard drive on my MacBook Pro? More options when flagging for migration I think there should be more Stack Exchange networks available when flagging a question to be migrated. For example I'd think that the following question:    ...would be a better fit on unix.stackexchange.com instead of Stack Overflow. But without the option to mark it so, I feel hesitant to mark it. How to connect two Dell P2415Q 4k displays to MacBook Pro 2016 What's the best way of connecting two Dell P2415Q 4k displays to the MacBook Pro 2016 with TouchBar and TouchID?  I have the monitors connected to an older MacBook Pro currently with two mini-DisplayPort cables. Can I somehow reuse those cables or do I need new ones?  Apple's support page  lets me know that:  "Note that although it uses a Mini DisplayPort connector, the Thunderbolt 3 (USB-C) to Thunderbolt 2 Adapter doesn't support connections to Mini DisplayPort displays."  So I guess reusing the cables is not the way to go? .NET Attributes: Why does GetCustomAttributes() make a new attribute instance every time? So I was playing around a little more with attributes in .NET, and realized that every call to Type.GetCustomAttributes() creates a new instance of my attribute. Why is that? I would think that the attribute instance would basically be a singleton-per-MemberInfo, with 1 instance bound to the Type, PropertyInfo, etc...  Here is my test code:  using System;  namespace AttribTest { [AttributeUsage(AttributeTargets.Class)] class MyAttribAttribute : Attribute {     public string Value { get; set; }      public MyAttribAttribute()         : base()     {         Console.WriteLine("Created MyAttrib instance");     } }  [MyAttrib(Value = "SetOnClass")] class MyClass { }  class Program {     static void Main(string[] args)     {         Console.WriteLine("Getting attributes for MyClass.");         object[] a = typeof(MyClass).GetCustomAttributes(false);         ((MyAttribAttribute)a[0]).Value = "a1";          Console.WriteLine("Getting attributes for MyClass.");         a = typeof(MyClass).GetCustomAttributes(false);         Console.WriteLine(((MyAttribAttribute)a[0]).Value);          Console.ReadKey();     } } }   Now if I were to implement attributes, I would expect the output to be:  Created MyAttrib instance Getting attributes for MyClass. Getting attributes for MyClass. a1   Where the "class loader" (sorry, I have more of a Java background, not 100% sure how .net loads its types) would compile MyClass, and create an instance of MyAttribAttribute, and store them together somewhere. (probably the Perm Gen in the heap if this were Java) The 2 calls to GetCustomAttributes() would then just return the same earlier created instance.  But the actual output is:  Getting attributes for MyClass. Created MyAttrib instance Getting attributes for MyClass. Created MyAttrib instance SetOnClass   So... why? It seems like creating a new instance of all these objects for every call is a bit excessive, and not good for performance/memory management.  Is there any way to always get the same instance over and over?  Anyone have any ideas why it was designed this way?  The reason I care at all is because I made a custom attribute that internally holds some validation information, so in the Attribute I basically have a "private bool Validated" that I set to true. The validation stuff takes a while, so I don't want to run it every time. Now the problem is that since it creates a new instance of the attribute each time I get the attributes, Validated is always "false".