java - why is my program skipping the if statement? -


this question has answer here:

i tried write program in different ways couldnt figure out .. program execute code under else even if condition verified can me please

here code :

table.addmouselistener(new mouseadapter() {      public void mouseclicked(mouseevent e) {          int row = table.getselectedrow();         int col = table.getselectedcolumn();         string path=table.getvalueat(row, col).tostring();         string equipementmoid=txt.gettext();          if(table.iscolumnselected(4) ){             if(table.getvalueat(row, 3).tostring()=="unit" ){                 string equipementdate2=combobox_10.getselecteditem().tostring();                 string xmlfile2=con.xmlselection(equipementdate2);                 getnode ne=new getnode();                 try{                     string equipementxml2=ne.nodetostring(xmlfile2, equipementmoid);                     system.out.println(equipementxml2);                     //getnodebypath node=new getnodebypath(equipementxml2,path);                 }                  catch (saxexception | ioexception | parserconfigurationexception e1) {                     // todo auto-generated catch block                     e1.printstacktrace();                 }             }                 else{                 string equipementdate1=combobox_9.getselecteditem().tostring();                 string xmlfile1=con.xmlselection(equipementdate1);                 getnode ne=new getnode();                 try{                     string equipementxml1=ne.nodetostring(xmlfile1, equipementmoid);                     getnodebypath node=new getnodebypath(equipementxml1,path);                 }                  catch (saxexception | ioexception | parserconfigurationexception e1) {                     // todo auto-generated catch block                     e1.printstacktrace();                 }             }                  }        } }); 

use string.equals(string other) function compare strings, not == operator.

the function checks actual contents of string, == operator checks whether references objects equal. if want test whether 2 strings have same value should use .equals()

 if(table.iscolumnselected(4) ){                 if(table.getvalueat(row, 3).tostring().equals("unit") ){ 

Comments