set - Searching in Hashcode doesn't work in Java -


i have

set tablica = new hashset(); 

and want search wrote this:

public void searchstudentbysurname() {     int = tablica.size();     if (0 >= a) {         joptionpane.showmessagedialog(null, "no data");     } else {         string s = joptionpane.showinputdialog(null, "give me surname");         iterator itr = tablica.iterator();         while (itr.hasnext()) {             string str = (string) itr.next();             if(tablica.equals(s)) {    // if doesn't work (1)                 joptionpane.showmessagedialog(null, str);             }          }      }  } 

}

i want know why (1) doesn't work.

you comparing string set, it's can't return true.

you meant compare str - str.equals(s), not necessary. can replace entire while loop tablica.contains(s). that's sets for.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -